Jump to content

Java Calc


GermanPrince
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...