Re:A game whose source code fits in one tweet
by wunderlust on Monday June 29, 2015 @11:32PM
(#9802762)
What exactly is happening here: "a.style.margin=++s+e%300"? (Specifically, the "++" part.)
[ Parent
| on HN ]
Re:A game whose source code fits in one tweet
by mgraczyk on Monday June 29, 2015 @11:37PM
(#9802784)
Increment 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.
Re:A game whose source code fits in one tweet
by andrewmunsell on Monday June 29, 2015 @11:37PM
(#9802787)
In 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".
Re:A game whose source code fits in one tweet
by SapphireSun on Monday June 29, 2015 @11:35PM
(#9802778)
s += 1
a.style.margin = (s + e) % 300