I am working on an assignment where I have to build a quiz app. I display questions one at a time. The user has to select one of the 4 answers from a group of radio inputs.
For some reason it only works when user selects first radio input, other get no response..
Here is my code :
var counter = 0;
var questions = ["<h3>What is the 9 + 10 </h3>\n\
<input type='radio' name = 'radio' class='rad' value ='19'>19\n\
<input type='radio' name = 'radio' class='rad' value ='23'> 23\n\
<input type='radio' name = 'radio' class='rad' value ='44'>66\n\
<input type='radio' name = 'radio' class='rad' value ='1'>123 ",
"<h3>What is the 5 + 10 </h3>\n\
<input type='radio' name = 'radio' class='rad' value ='15'>15\n\
<input type='radio' name = 'radio' class='rad' value ='23'> 23\n\
<input type='radio' name = 'radio' class='rad' value ='44'>44\n\
<input type='radio' name = 'radio' class='rad' value ='1'>12 "
];
document.getElementById("question").innerHTML = questions[counter];
document.querySelector('.rad').addEventListener("change", nextQuestion);
function nextQuestion() {
console.log(counter);
counter++;
document.getElementById("question").innerHTML = questions[counter];
}