| re: I have an error. I am brain dead. Please give me a hint
[HTML]
<html>
<title>Math Quiz</title>
<script>
var tooLong = false;
function recordAnswer(question, answer) {
if (question == 1) {
document.getElementById("studentAnswer1").value = answer;
}
if (question == 2) {
document.getElementById("studentAnswer2").value = answer;
}
if (question == 3) {
document.getElementById("studentAnswer3").value = answer;
}
}
function test() {
alert("test");
}
function scoreQuiz() {
allanswers = true;
if (document.getElementById("studentAnswer1").value == "" || document.getElementById("studentAnswer3").value == "" || document.getElementById("studentAnswer2").value == "") {
allanswers = false;
}
if (tooLong == true) {
alert("You ran out of time! You must retake the test by reloading the Web page.");
return false;
}
var correct = 0;
if (allanswers) {
if (document.getElementById("studentAnswer1").value == document.getElementById("answer1").value) {
++correct;
}
if (document.getElementById("studentAnswer2").value == document.getElementById("answer2").value) {
++correct;
}
if (document.getElementById("studentAnswer3").value == document.getElementById("answer3").value) {
++correct;
}
if (correct == 3) {
alert("You got all 3 correct!");
} else {
alert("You scored "+correct+" answers correctly.");
}
return true;
} else {
alert("You have to answer all questions!");
}
}
</script>
<body onload="setInterval('tooLong=true;', 600000);">
<h1>Math Quiz</h1>
<p>Select the correct answer to the following math problems, then
select the Score Quiz button.</p>
<p><b>1.</b> 84 divided by 7 is equal to _____.</p>
<p>
<input type="radio" name="question1" value="6" onclick="recordAnswer(1, this.value);">6<br>
<input type="radio" name="question1" value="7" onclick="recordAnswer(1, this.value);">7<br>
<input type="radio" name="question1" value="9" onclick="recordAnswer(1, this.value);">9<br>
<input type="radio" name="question1" value="12" onclick="recordAnswer(1, this.value);">12</p>
<p><b>2.</b> What is the value of x in the equation <b>x * 12
= 156</b>.</p>
<p><input type="radio" name="question2" value="5" onclick="recordAnswer(2, this.value);" />5<br />
<input type="radio" name="question2" value="11" onclick="recordAnswer(2, this.value);" />11<br />
<input type="radio" name="question2" value="13" onclick="recordAnswer(2, this.value);" />13<br />
<input type="radio" name="question2" value="19" onclick="recordAnswer(2, this.value);" />19</p>
<p><b>3.</b> What is the square root of 196?</p>
<p><input type="radio" name="question3" value="7" onclick="recordAnswer(3, this.value);" />7<br />
<input type="radio" name="question3" value="14" onclick="recordAnswer(3, this.value);" />14<br />
<input type="radio" name="question3" value="28" onclick="recordAnswer(3, this.value);" />28<br />
<input type="radio" name="question3" value="98" onclick="recordAnswer(3, this.value);" />98</p>
<p><input type="button" value=" Score Quiz" onclick="scoreQuiz();" /></p>
<p><input type="hidden" name="answer1" id="answer1" value="12" /> <input type="hidden" name="answer2" id="answer2" value="13" /> <input type="hidden" name="answer3" id="answer3" value="14" /> <input type="hidden" name="studentAnswer1" id="studentAnswer1" value="" /> <input type="hidden" name="studentAnswer2" id="studentAnswer2" value="" />
<input type="hidden" name="studentAnswer3" id="studentAnswer3" value="" /></p>
</body>
</html>
[/HTML]
Heres your fix I tried to not modify the code too much so you could see what is happening.
|