Help me debug this, thanks. | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
0

Help me debug this, thanks.

/*please help me debug this, x+y isn't adding both but concentates them unlike the others, also <br> tags aren't working, thanks.*/ var x; var y=5; var x=prompt("what is x?"); var z= x + y; var a=x*y; var b=x-y; y document.write(z);"</br>" document.write(a);"</br>" document.write(b); https://code.sololearn.com/Wkb87MP3Hjvd/?ref=app

8th May 2018, 1:14 AM
Gracious
Gracious - avatar
3 Respuestas
+ 2
In JS, Plus (+) is used as concat operater, by default if you add two numbers they will be parsed to strings and will be concatenated, in order to add two values you need to parse them var x; var y = 5; var x = prompt("what is x?"); var z = parseFloat(x) + parseFloat(y); var a = x * y; var b = x - y; document.write("Addition: " + z); document.write("</br>"); document.write("Multiplication: " + a); document.write("</br>"); document.write("Substraction: " + b);
8th May 2018, 1:33 AM
Naresh
Naresh - avatar
+ 1
Here is the simplified example https://code.sololearn.com/Wz0Yh2dqVtvX#js
8th May 2018, 1:43 AM
Naresh
Naresh - avatar
+ 1
wow, thanks I never knew about the parse property in js, we do of a truth learn everyday, and seems solo learn didn't mention it. and also the br tag now works, thanks.
9th May 2018, 5:33 AM
Gracious
Gracious - avatar