0

A question about JavaScript

I have a question about this code. I don’t know what “ count++ % 2 ==0 “ mean. Especially “count++”. Is this like “0 % 2” and the next one is “1 %2”? It doesn’t seem it’s looping and adding one to count variable. var count = 0; function clickMe(e) { if (count++ % 2 == 0) { e.textContent = “o”; } else { e.textContent = “x”; } }

2nd Jul 2018, 12:53 PM
aaa
3 Answers
+ 7
Thnx Louis
2nd Jul 2018, 5:12 PM
Agent
Agent - avatar
+ 5
count++ is an increment of 1 so one is added on to count % is the modulus operator This finds a remainder after a division Such as: 5 % 2 = 1 This is becuase 5/2 only lets 2 go up to 4 Therfore, 5%2 is 5-4 which is 1 == Is the equality operator
2nd Jul 2018, 1:29 PM
Agent
Agent - avatar
+ 3
Agent Nice indentation!
2nd Jul 2018, 5:02 PM
Louis
Louis - avatar