You're right on track – It gets the correctAnswer
of the current question – ie. '2' for the first question, meaning the third option in the array (since 0, is always the first position in an array)
if you look at the HTML, the ID for the third radio button is choice3
so the script increments to determine if the proper radio button is is punched (.checked
returns true/false), if it is, then they were right, so the score is bumped up!
A better initial design could have been:
<h3 id="questionHeader"></h3>
<input type="radio" name="choice" value="0" id="choice0">
<label id="answ0"></label>
<br>
<input type="radio" name="choice" value="1" id="choice1">
<label id="answ1"></label>
<br>
<input type="radio" name="choice" value="2" id="choice2">
<label id="answ2"></label>
<br>
<button id="next">Next</button>
To prevent the extra step in the javascript, and match both the form values, and the array positions.