GermanPrince Posted July 31, 2009 Share Posted July 31, 2009 I made this neat little calculator. Multiplication, division, and subtraction work fine, but when I do addition it takes it a little to seriously. Here is the code I use for addition. function add(){ var y=prompt("Insert Y","Y"); var x=prompt("Insert X","X"); var z=y+x alert(y+" + "+x+" = "+z);} Link to comment Share on other sites More sharing options...
Ingolme Posted July 31, 2009 Share Posted July 31, 2009 Try this: var z = parseFloat(y) + parseFloat(x) In Javascript, the concatenation operator is the same as the addition operator. It can be confusing at times. Link to comment Share on other sites More sharing options...
GermanPrince Posted August 1, 2009 Author Share Posted August 1, 2009 Danke, that should make it easier to do stuff with JavaScript. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.