Hello friends,
I’m trying to write a function that will display all of the colors in the current pattern of a game of Simon. The function should be timed in that it will display one color every couple seconds. However, the function is not working. Instead of iterating through the pattern, it just turns on all the colors in the pattern at once. Here’s the code I have so far:
// This function displays all of the colors in the current pattern.
function displayPattern() {
for (var i = 0; i < currentPattern.length; i++) {
setTimeout(lightColor(currentPattern[i]), (i * 2000) + 1000);
}
}
function lightColor(color) {
// code to “light up” the chosen color
}
I know that the lightColor function works because I can see that the colors. Any ideas what I’m doing wrong?