I am programming a calculator, and I have come across a problem. The programming and the mathematics that the programming is based on do not match up. I’ll provide the code 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();
});
The consists of 4 html textboxes which each require integer input. The code produces the following output:
*In the time it takes me to Enter something here, Barack Obama makes $MoneyMadeDuringActivity *
I tested this code by simply entering 1 in each textbox. It should be $24,192.46, but instead I’m getting $28,619.74. What am I doing wrong? Please help!
You missed a decimal point in the
minutesmultiplier. It looks like it should be44.72, not4472.