+ 2

Could someone explain me how this code works line to line? Thanks.

var two=5; var five=8; var eight=3; var three=two+eight%five; var ten=two*three%eight; alert(ten);

26th May 2018, 7:38 PM
Rastislav Romanec
Rastislav Romanec - avatar
3 ответов
+ 3
var three=5+3%8; three=5+3=8; var ten=5*8%3; ten=40%3=1 //output is 1
26th May 2018, 7:44 PM
᠌᠌Code X
᠌᠌Code X - avatar
+ 3
I have put comments in your code to explain: var two=5; var five=8; var eight=3; var three=two+eight%five; // var three = 5 + 3 % 8 // you do % first and + after that // 3 % 8 = 3. 5 + 3 = 8. three = 8 alert (three); var ten=two*three%eight; // var ten = 5 * 8 % 3 // 5 * 8 = 40. 40 % 3 = 1 alert(ten);
26th May 2018, 7:53 PM
Paul
Paul - avatar
+ 2
multiplication is before modulus and addition is behind?
26th May 2018, 7:56 PM
Rastislav Romanec
Rastislav Romanec - avatar