Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I ran into this question on sololearn.. Why is the answer 36 and not 6?

JavaScript
var x = 326;

var prod = 1;

while (x>0) {
    prod *= x%10;
    x = (x-x%10)/10;
    }

console.log(prod);


What I have tried:

All the challenges on the website are timed.. so this one was maybe 10 seconds. I have been looking over it for a while now... no pun intended...
Posted
Updated 11-Aug-17 12:01pm
v2

Because 6 * 3 * 2 = 36 ... the modulus pulls out each least significant digit in turn.
 
Share this answer
 
Quote:
Does modulus while loop have a different outcome when in while loop?

This question makes no sense to me.
Quote:
Why is the answer 36 and not 6?

The answer is 36 because the code is the code.
6 only makes sense if the question is about the effect of the "while loop" in this code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900