+ 4

Operators in JavaScript

I am a little confused by this code could someone be kind enough to explain? The answer is 36, but I don’t understand why. var x = 326; var prod = 1; while (x > 0) { prod *= x % 10; x = (x - x % 10) / 10; } document.write (prod);

23rd Apr 2018, 1:48 AM
Levi
Levi - avatar
6 Answers
+ 6
I don't know how familiar you are with this stuff so here is a very detailed answer. Open the code and go to the JS tab. Read the comments https://code.sololearn.com/WMLBCm2P3PpA/?ref=app
23rd Apr 2018, 2:02 AM
cyk
cyk - avatar
+ 5
â˜ș Happy to help! And the forum is awesome indeed!
23rd Apr 2018, 2:10 AM
cyk
cyk - avatar
+ 5
When it comes to loops you must keep going back until the condition becomes false
23rd Apr 2018, 2:11 AM
cyk
cyk - avatar
+ 4
Of course. Some times I make things more complicated than they are. I need another perspective to remind me... loops loop. Lol thank you, cyk.
23rd Apr 2018, 2:19 AM
Levi
Levi - avatar
+ 3
That is an AWESOME explanation. I got as far as 32 but wasn’t going back each time. Thank you for the very cool and thoughtful response. I get it now. The forum is the best.
23rd Apr 2018, 2:09 AM
Levi
Levi - avatar
0
I need to practice math to dominate this topic. I was a little bit confused as well.
3rd Sep 2020, 8:45 PM
David