I have a form that I set up as a quiz to take. Eventually I will alter it to calculate the final score of the quiz once done. But I am stuck on this one part. I want to add a point if a right box is checked, and subtract a point if a wrong box is checked.
Code for a right answer:
<input type="checkbox" name="q3" id="q1javascript" answer="true">
Code for wrong answer:
<input type="checkbox" name="q3" id="q3xhtml" answer="false">
Javascript checking against it:
function test() {
var boxes = document.getElementsbyName('q3');
var score = 0;
var i = 0;
while (i < 4) {
var answer = boxes[i].getAttribute('answer');
if (answer === 'true') {
score++;
}
else {
score--;
}
i++;
}
alert(score);
}