0

I've been trying to make a calculator with javascript. Whenever I select Pythagorean Theorem, then input the values that it is supposed to solve it returns NaN. I'm not sure why it doesn't return a value.

$(function() {
$('#aValue').hide();
$('#bValue').hide();
$('#cValue').hide();
$('#pythagoreanTheorem').click(function() {
    $('#aValue').show();
    $('#bValue').show();
    $('#cValue').show();
$('#resultButton').click(function() {
    var aValue = document.getElementById("aText");
    var bValue = document.getElementById("bText");
    var result = (aValue*aValue)+(bValue*bValue)
    $('#result').text(result);
    });
});

});



function dropDownBox() {
    document.getElementById("myDropdown").classList.toggle("show");
}

function filterFunction() {
    var input, filter, ul, li, a, i;
    input = document.getElementById("myInput");
    filter = input.value.toUpperCase();
    div = document.getElementById("myDropdown");
    a = div.getElementsByTagName("a");
    for (i = 0; i < a.length; i++) {
        if (a[i].innerHTML.toUpperCase().indexOf(filter) > -1) {
            a[i].style.display = "";
        } else {
            a[i].style.display = "none";
        }
    }
}
  • NaN means not a number, i suspect you used strings instead of numbers somewhere, don't forget to parse. – xDreamCoding Oct 07 '17 at 23:38
  • GetElementById is giving you the textbox. To get the actual contents of the textbox add .val() afterwards https://stackoverflow.com/questions/463506/how-do-i-get-the-value-of-a-textbox-using-jquery – anotherfred Oct 07 '17 at 23:40

0 Answers0