What is a better workaround to this, rather than repeating this numerous times for 10 different elements?
Html:
<div id="rightWrongContainer">
<div id="q1" class="rightWrong"></div>
<div id="q2" class="rightWrong"></div>
<div id="q3" class="rightWrong"></div>
<div id="q4" class="rightWrong"></div>
<div id="q5" class="rightWrong"></div>
<div id="q6" class="rightWrong"></div>
<div id="q7" class="rightWrong"></div>
<div id="q8" class="rightWrong"></div>
<div id="q9" class="rightWrong"></div>
<div id="q10" class="rightWrong"></div>
</div>
Js:
if (counter == 1 && answer == userInput){
var green = document.getElementById("q1").style.backgroundColor="green";
}
else {
var red = document.getElementById("q1").style.backgroundColor="red";
}
Aucun commentaire:
Enregistrer un commentaire