Skip to content

Instantly share code, notes, and snippets.

@adregan adregan/colorscript.js

Last active Aug 29, 2015
What would you like to do?
// stashes the box
var box = document.getElementById('box');
// Sets a 1 ms interval to call clickThemAll()
setInterval(clickThemAll, 1);
// Clicks the play button to start the game
function clickThemAll(){
//grabs the children, sets prevBG to false, stores length
var children = box.querySelectorAll('span')
, prevBG = false
, len = children.length
for (i = 0; i < len; ++i) {
// grabs the background
var background = children[i].style.background;
// checks if the background is different than the previous. If so, clicks.
if (prevBG && prevBG !== background) {
// If none of them are different than the first one is the square to click
else if (i === (len - 1)) {
// set the prevBG to the current background
prevBG = background;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.