+ 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
1 Resposta
+ 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.