Hi, the link to my codepen is: https://codepen.io/glennqhurd/pen/EQqxKe
The specific code I need help with is on line 93. Here’s the code block:
function buttonSequence(count) {
for (var i = 0; i < count; i++) {
if (moveList.length < i + 1) {
var random = Math.floor(Math.random() * 4);
moveList.push(colorList[random]);
}
//for (var j = 0; j <= i; j++) {
var sequence = setInterval(function() {
switch (moveList[count]) {
case "red":
buttonFlashRed($("#arc1"));
break;
case "blue":
buttonFlashBlue($("#arc2"));
break;
case "yellow":
buttonFlashYellow($("#arc3"));
break;
case "green":
buttonFlashGreen($("#arc4"));
break;
}
count++;
if(moveList.length <= count) {
clearInterval(sequence);
count = 0;
}
}, 300);
}
}
The problem is when the code gets to
var sequence = setInterval(function() {
it ignores the code and skips ahead to the top of the for loop. I don’t know if it’s because of the way for loops work in Javascript but I need it because I’m trying to get the computer to generate a sequence based off of a given number and list that stores the moves. I’m stumped. (Also, it was working w/o the setInterval but the buttons would be flashing simultaneously.)