0
Why the plus operator not working well
7 Answers
+ 1
use parseInt(or parseFloat), like these :
res = parseInt(a) + parseInt(b) or
input=parseInt (prompt(...))
+ 1
const input1 = Number(prompt("Enter first num: "));
const operator = prompt("Enter an operator");
const input2 = Number(prompt("Enter second num: "));
0
It working like concatination because prompt accept string type basically..
Convert into into number type value by
const input1 = Number(prompt("Enter first num: "));
Or
const input2 = +prompt("Enter first num: ");
Both value..
For, other it will automatically converted but for plus, it works both ways : addition and concatination overloaded operator...
Hope it helps...
0
Xushnudbek Isaqov
Jayakrishnađźđł
I tried your recommendation but unfortunately not working still.
0
What have you tried?
How you tried it?
It works. . All 3 ways.. Do check again.
edit: Muhammad Abdulmalik
convert input1 and input2 into number
0
use it only for numbers not for operator
0
Hi Muhammad Abdulmalik update your code with what you have tried. Just reopen it add your changes and save. Then we can see why its not working :) Thanks