Jump to content

Java Calc


GermanPrince

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...