I have a function which is used as part of a calculator. I had it minified with JSMin. I rewrote the code so I could debug the code, but now that I rewrote the code I found a new bug (the new bug being the NaN problem). The output should be a number, but is instead NaN. The code is shown below.
function calculate() {
console.log(1);
var activity = $("#txtActivity").val();
var days = parseInt( $("#txtDays").val(), 10);
var hours = parseInt( $("#txtHours").val(), 10);
var minutes = parseInt( $("txtMinutes").val(), 10);
var seconds = parseInt( $("txtSeconds").val(), 10);
var MoneyMadeDuringActivity = (days * 21464) + (hours * 2683) + (minutes * 4472) + (seconds * 0.74);
$("#CalcOutput").html("In the time it takes me to " + activity + ",<br />Barack Obama makes $" + MoneyMadeDuringActivity);
}
$("#btnCalculate").click(function() {
calculate();
});
I’m having trouble figuring out how to get rid of this bug, since “activity” is the only string variable, and all the other variables are numbers or are parseInt’ed.
This is the output I am getting:
In the time it takes me to Enter something here, Barack Obama makes $NaN
You’re missing the
#in the following lines:Because nothing is found by the selector, it’s effectively: