0
javascript question to a challenge
var i = 12; (++i) % 3; alert(i); my solution was: 1 the right solution was : 13; but why? can someone plz explain to me why 13?
3 odpowiedzi
+ 3
Because you've increment i of one so i is 13
If the question was :
var i = 12
i = (++i) % 3
alert(i)
The solution is 1
+ 1
this look like a little trick question, (++i) % 3; actually do nothing except increment the variable i. So you thought that the result was 13 % 3 = 1, but this result isn't being stored anywhere. The alert only print the new i wich is now 13.
0
thank you! 😊 my mistake. 🤭