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!!
2 odpowiedzi
+ 2
Use == not =. By using = it will take that value. like
if(select1='+')
now value of select1 is +. use
if(select1=="+")
0
You have to test using == and not =.
Here, you say "if select1 can be assigned to '+'", not "if select1 is '+'".