Why is the JavaScript not working? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why is the JavaScript not working?

I used to write this code to reverse "a" and "b", and it reverses "a" without any problems, but it cant reverse "b". Can anyone help? Code: var a = prompt("Enter your number"); document.write = ("Your number of choise is = " + a); var A = (a.split('').reverse().join('')); if (a >= A) { var b = a - A; var B=(b.split('').reverse().join('')); } else if (A > a) { var b = A - a; var B=(b.split('').reverse().join('')); } or my full code https://code.sololearn.com/We0Gf6LZpBL9/?ref=app

3rd Apr 2018, 10:00 AM
Roel
Roel - avatar
1 Answer
+ 1
https://code.sololearn.com/Wfrx7kxFrLIM/?ref=app You could use recursion to finish this. Although, a while loop would also suffice. Update, I added comments, and used better variable names. This is why good variable names and comments are essential to reducing bugs, and increasing maintainability.
3rd Apr 2018, 10:33 AM
Emma