+ 1

Explain please

I try to code simple calculator on JavaScript, here is my first steps to it. Last if block doesn't work, explain please, why? https://code.sololearn.com/WG52lieN7zkK/?ref=app

23rd Jul 2020, 4:06 PM
Maksim Rukavishnikov
Maksim Rukavishnikov - avatar
3 Answers
+ 4
Use Number(a) as it returns a boolean 1 if successful else 0 https://code.sololearn.com/WFC4t4O77vn5/?ref=app
23rd Jul 2020, 4:08 PM
Saphal Poudyal
Saphal Poudyal - avatar
+ 1
Maksim Rukavishnikov The inputs you receive are of type "string", you need them to be in type number/integer/floats, so that you can add them. num1 = "20" num2 = "40" num1 + num2 = "2040" So to prevent this, use parseInt() parseInt(num1) + parseInt(num2) I would suggest using parseFloat so that it takes floats(decimals) too rather than just simple integers (1,2,3)
23rd Jul 2020, 6:17 PM
maf
maf - avatar
0
Thank you!
23rd Jul 2020, 4:50 PM
Maksim Rukavishnikov
Maksim Rukavishnikov - avatar