+ 1

why?

What is the output of this code? var a = 66; var b = a % 4; var c = b % a; alert(c); answer 2

24th Aug 2018, 2:03 PM
Алмат Айтбаев
Алмат Айтбаев - avatar
7 ответов
+ 2
The "%" operator represents modulus division. It gives the reminder after the division. First operation b = 66 % 4 = 2 (because 16*4= 64 => reminder is 2). Second operation c = 2 % 66 (here the reminder is 2, because 2 < 66).
24th Aug 2018, 2:22 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 2
You should get whole number after the division and check the reminder. So in this case it is not possible and 2 is the reminder.
24th Aug 2018, 2:38 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 2
Another try to explain it 2 % 66 => 1 times 66 is 66 > 2, so it's not possible, 0 times 66 is 0 and the reminder is 2 - 0 = 2.
24th Aug 2018, 2:44 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
что именно ты хочешь вывести
24th Aug 2018, 2:18 PM
Learner
0
2/66=0,030303030303
24th Aug 2018, 2:28 PM
Алмат Айтбаев
Алмат Айтбаев - avatar
0
почему вторая операция деление по модулю 2%66 равно на 2 ?
24th Aug 2018, 2:38 PM
Алмат Айтбаев
Алмат Айтбаев - avatar
0
whenever you do x%y, output will be x if you have y>x == true
24th Aug 2018, 2:50 PM
E_E Mopho
E_E Mopho - avatar