What error in the following code would result in if(is1Pressed = true) console logging “1” repeatedly in console
if(is1Pressed = true){
console.log("1");
p.innerHTML = "<audio autoplay='autoplay' src='button1.wav'/>";
}
else if(is2Pressed = true) {
console.log=("2");
p.innerHTML = "<audio autoplay='autoplay' src='button1.wav'/>";
}
else if(is3Pressed = true) {
p.innerHTML = "<audio autoplay='autoplay' src='button1.wav'/>";
}
else if(is4Pressed = true) {
p.innerHTML = "<audio autoplay='autoplay' src='button1.wav'/>";
}
else if(is5Pressed = true) {
p.innerHTML = "<audio autoplay='autoplay' src='button1.wav'/>";
}
else
{
p.innerHTML = "<audio autoplay='autoplay' src='button1.wav'/>";
}
You are using
=, the assignment operator, instead of==or===. That said, you can stop checking explicitly againsttrueand just check the variable’s truthiness for more concise code: