3 ms·
What exactly is happening here: "a.style.margin=++s+e%300"? (Specifically, the "++" part.)
by wunderlust 11y ago
What exactly is happening here: "a.style.margin=++s+e%300"? (Specifically, the "++" part.)
- marpstar 11y agoincrements `s` before evaluating the expression and adds it to (e % 300)
- username 11y ago++ will increment s before the new margin is set.
- SapphireSun 11y agos += 1 a.style.margin = (s + e) % 300
- mgraczyk 11y agoIncrement global state variable, add it to e, which is the number of milliseconds the game has been running modulo 300. Then set the margin size to that value. It's a simple pseudo-pseudorandom number generator.
- andrewmunsell 11y agoIn case any one was wondering the difference between "s++" and "++s" (the former of which is probably more common), prepending the "++" increments the variable before returning it, whereas appending it would increment after returning the value. The code you posted is essentially equivalent to "s = s + 1; a.style.margin = s + e % 300".