0

I made a simple script to add, subtract, multiplie and divide, but it just works for adding, do you guys know how to make it wor

var number1=prompt('please insert first number') var select1=prompt('Now, insert what do you want: + to adding, - to subtracting, * to multiplication and / to division') var number2=prompt('insert the second number') number1= Number(number1) number2= Number(number2) if(select1='+'){ alert(number1+number2) } else if(select1='-'){ alert(number1-number2) } else if(select1='*'){ alert(number1*number2) } else if(select1='/'){ alert(number1/number2) } else{ alert('sorry, try again') } Thanks!!

27th Nov 2016, 12:00 PM
Losel Matos
Losel Matos - avatar
2 ответов
+ 2
Use == not =. By using = it will take that value. like if(select1='+') now value of select1 is +. use if(select1=="+")
27th Nov 2016, 12:52 PM
Aditya kumar pandey
Aditya kumar pandey - avatar
0
You have to test using == and not =. Here, you say "if select1 can be assigned to '+'", not "if select1 is '+'".
27th Nov 2016, 12:05 PM
Pierre Varlez
Pierre Varlez - avatar