+ 1

# Modulo - JavaScript Challenge

What is the output of this code? var a = 66; var b = a%4; var c = b%a; alert(c); /* My thinking: var b = 66/4= 16.5 (remainder 2, so b=2). Next, c=2%66 or 2/66 = 1/33 or .03 which I rounded down to floor of 0. I and my challenger both got this one wrong. 🤷🏽‍♀️

15th Mar 2022, 7:17 PM
Tahiti🌍Castillo
+ 3
You can copy the code into a script on playground and test it there to see what happens. Example: 4%40 = 4 How often does 40 go in 4? 0 times, so 4 is left as remainder.
15th Mar 2022, 7:34 PM
Lisa
+ 2
Jayakrishna🇮🇳 Thank you. What I really had trouble with was b%a (2%66). The rest of it, I understood. Thank you.
16th Mar 2022, 12:18 AM
Tahiti🌍Castillo
+ 1
Lisa Ok. Thank you. I think I have it now. Anytime the denominator is larger than the numerator, the % will be the numerator itself.
16th Mar 2022, 12:15 AM
Tahiti🌍Castillo
0
% returns reminder / returns quotient 66/4 = 16 , => 16*4=64 66%4 = 2 , => 66 - 16*4 = 2 reminder (since 16*5 exceeds 66, 16*4+2=66 )
15th Mar 2022, 8:35 PM
Jayakrishna 🇮🇳