My question is: what is the most intelligent way to use a for loop which affects CSS via jQuery and a timer together?
Here's a fiddle:
Below is my attempt at implementing a timer which defines a certain amount of time that you can either press the enter key, or not press the enter key, and depending on the situation, it will push a value to an array.
setTimeout(function(){
if(e.which == 13){
choice = 1;
} else {
choice = 0;
}
if(nBack == randomNumber){
if(choice == 1){
correct.push(0);
} else if(choice == 0){
incorrect.push(0);
}
} else {
if(choice == 0){
correct.push(0);
} else if(choice == 1){
incorrect.push(0);
}
}
}, 1000 * i * y)();
and here's the portion which should select a certain css id, then edit it based on a random number being chosen:
randomNumber = Math.floor( Math.random() * (m+1) );
while(randomNumber === history[i-1]){
randomNumber = Math.floor( Math.random() * (m+1) );
}
$("." + randomNumber).css({ "background-color": "#ffe"});
history[i] = randomNumber;
I have gotten it running without the timer with just alerts, and I have also gotten the timer to work, but upon trying to integrate the two and have it affect CSS, it won't work.