I'm trying to run a function called "reset" in an event listener but I get the error "reset" is not a function at HTMLButtonElement.
for(var i = 0; i < gameMode.length; i++){
gameMode[i].addEventListener("click", function(){
for(var i = 0; i < gameMode.length; i++){
gameMode[i].classList.remove("selected");/*this line initially removes the class "selected" from all elements*/
this.classList.add("selected");/*it then adds it only to the element that was clicked*/
}
this.textContent === "Easy" ? numSquares = 3: numSquares = 6;
reset();
})
}
function reset(){
reset.innerHTML = "New Colors";
resultDisplay.innerHTML = "";
h1.style.backgroundColor = "steelblue";
colors = randomColorArr(numSquares);
pickedColor = pickColor();
//console.log("value of picedColor inside reset event listener: "+pickedColor);
colorDisplay.innerHTML = pickedColor;
for (var i = 0; i < squares.length; i++){
squares[i].style.backgroundColor = colors[i];
}
}
I just realised I had set "reset" earlier in my js code to another variable. Renaming the earlier variable from " reset" to something else solved the issue.
Rookie mistake.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.