Been racking my brains wondering why this function doesn’t execute properly. I am trying to make a simple quiz, and while the function does verify wether Q1 is correct, it does not proceed from there and mark the other two questions, nor calculate a total. Can anyone help me?
<html>
<head>
<title>Session 10, Exercise 1</title>
<script type=”text/javascript”>
function markQuiz()
{
var correct = 0;
var nw = window.open();
var answer1 = document.getElementById(“Q1”).value;
if (answer1 == “John”)
{
correct++;
nw.document.write (“<p>Answer 1 was correct</p>”);
}
else
nw.document.write (“<p>Answer 1 was wrong</p>”);
var answer2 = document.getElementById(‘Q2’).value;
if (answer2 == Waratah)
{
correct++;
nw.document.write (“<p>Answer 2 was correct</p>”);
}
else
nw.document.write (“<p>Answer 2 was wrong</p>”);
var answer3 = “none”;
if (quiz.Q3[0].checked)
answer3 = quiz.Q3[0].value;
if (quiz.Q3[1].checked)
answer3 = quiz.Q3[1].value;
if (quiz.Q3[2].checked)
answer3 = quiz.Q3[2].value;
if (answer3 == “Canberra”)
{
correct++;
nw.document.write (“<p>Answer 3 was correct</p>”);
}
else
nw.document.write (“<p>Answer 3 was wrong</p>”);
nw.document.write (“<p>Total answers correct = ” + correct + “</p>”);
nw.document.write (“<input type=’button’ value=’back’ onClick=’window.close();’>”);
}
</script>
</head>
<body>
<h1>General Knowledge Quiz</h1>
<form name=”quiz” id=”quiz”>
<h2>Q1</h2>
<p>What is the first name of Australia’s current Prime Minister</p>
<input type=”text” id=”Q1″ name=”Q1″ />
<h2>Q2</h2>
<p>What is the official state flower of NSW?</p>
<select id=”Q2″ name=”Q2″>
<option value=”Carnation” checked=”checked”>Carnation</option>
<option value=”Waratah”>Waratah</option>
<option value=”Azalea”>Azalea</option>
</select>
<h2>Q3</h2>
<p>Please choose the capital of Australia:</p>
<input type=”radio” name=”Q3″ value=”Sydney” checked=”checked”>Sydney</input><br />
<input type=”radio” name=”Q3″ value=”Melbourne”>Melbourne</input><br />
<input type=”radio” name=”Q3″ value=”Canberra”>Canberra</input><br /><br />
<input type=”button” value=”Mark Quiz” onClick=”markQuiz();”>
</form>
</body>
</html>