Incorrect javascript calculations

dalton.lesko088

Baseband Member
Messages
55
Location
USA
why wont my javascript execute this the right way?

var tax1= ($("income").value*.1);

if(income <= 20000) {
$("Results").value="First Name:" + " " + $('FName').value + "\n" + "\n" +
"Last Name:" + " " + $('LName').value + "\n" + "\n" +
"Phone Number:" + " " + $('phone').value + "\n" + "\n" +
"Zip Code:" + " " + $('zip').value + "\n" + "\n" +
"Email Address:" + " " + $('email').value + "\n" + "\n" +
"YOB:" + " " + $('year').value + "\n" + "\n" +
"Social:" + " " + $('social').value + "\n" + "\n" +
"Income:" + " " + $('income').value + "\n" + "\n" +
"Tax:" + " " + tax1 + "\n" + "\n" +
"Net Income:" + " " + ($("income").value-tax1);
};
say income's value is 20000. it says that tax (20000*.1) is -3500 and therefore net income is 23500 when tax should be 2000 and net income should be 18000... i dont get it.
 
Last edited:
Well if your if statement, you only have "income" and not " $("income").value "

Make sure your tax1 calculation is correct by outputting the value that's being retrieved from $("income").value
 
Well if your if statement, you only have "income" and not " $("income").value "

Make sure your tax1 calculation is correct by outputting the value that's being retrieved from $("income").value
I changed my if statement to say $("income").value instead of income. but i did have a variable declared called income thats why i had it set to that. but it still doesnt work
 
I ran the following on JSFiddle and it came out with the correct answer:

Code:
var income = 20000;
var tax = income * .1; 
var netIncome = income - tax;

console.log(income);
console.log(tax);
console.log(netIncome);

And it came out correct. So you'll need to add some debugging statements (such as console.log() calls or outputting to an HTML element or something) to see what values are being retrieved from your income text box.
 
Back
Top Bottom