Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can someone please help me with thi

Status
Not open for further replies.

kxo129

Technical User
Jan 7, 2003
6
US
can someone please help me with this simple javascript code:

var labor;
labor=prompt("Enter your labor cost","");
var material;
material=prompt("Enter your material cost","");
var cost;
cost=labor + material;
{
alert ("Your total cost is " + cost + ".");
}

the problem is the 6th line...instead of actually adding the numbers that the user inputs (labor and material), that line just puts the two numbers together. So for example if the user enters $4,000 for labor cost and $5,000 for material cost, the total cost is 40005000 instead of $9,000.

Please help!
 
try changing this
cost=labor + material;

to this
cost = parseFloat(labor) + parseFloat(material);


=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top