Grains in JavaScript