It is adding 1+2 as 12 !!! Whereas substraction is perfect.. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

It is adding 1+2 as 12 !!! Whereas substraction is perfect..

https://code.sololearn.com/WBZJ6VJGd5u0/?ref=app

24th Jan 2018, 10:53 AM
Radha Bagadi
Radha Bagadi - avatar
3 Answers
+ 7
You should add parseInt function to make them numbers first. See the code :- https://code.sololearn.com/Wl4Wghz5Cv9e/#js
24th Jan 2018, 11:01 AM
Akash Pal
Akash Pal - avatar
+ 8
try: alert(Number(x)+Number(y)); - It is treating user input as a string.
24th Jan 2018, 10:59 AM
jay
jay - avatar
+ 4
It is just because the parameters are string. For the + operation the program will join x and y. But the - operator doesn't exist for string, so the program will convert x and y to integers.
24th Jan 2018, 12:19 PM
Αητοιπe
Αητοιπe - avatar