Now it all works but as soon as i add more than four questions it stops working. and the calculation of how many answers are correct do not calculate correctly. here is the code that works with four questions:
<html>
<head>
<script = "javascript">
document.write('<center><b><font color="#0000FF" font size=18>Binary Quiz</font></b></center>');
document.write("<br clear=all>");
document.write('This quiz is for those with the basic knowledge of Binary numbers, have fun and enjoy!');
document.write("<br clear=all>");
function show_alert()
{
alert("Think - binary, convert decimal numbers into binary first if it helps, for example, 1=?, 2=?, 3=0011");
}
function myResult(){
correctanswers = 0;
if (document.myForm.q1[0].checked) correctanswers++;
if (document.myForm.q2[1].checked) correctanswers++;
if (document.myForm.q3[2].checked) correctanswers++;
if (document.myForm.q4[3].checked) correctanswers++;
document.getElementById("correct1").style.backgroundColor="yellow";
document.getElementById("correct2").style.backgroundColor="yellow";
document.getElementById("correct3").style.backgroundColor="yellow";
document.getElementById("correct4").style.backgroundColor="yellow";
return correctanswers;
}
function showResult(){
correctAnswers2 = myResult();
alert("You have answered" + correctAnswers2 + "answers correctly!");
}
</script>
</head>
<body>
<input type="button" onclick="show_alert()" value="Hint" />
<form name="myForm" action="">
<center>
<p>
<IMG SRC=Game\0.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><br />
<input type="radio" name="q1" /> -1 <br />
<input type="radio" name="q1" /> 0 <br />
<input type="radio" name="q1" id = "correct1"/> 1 <br />
<input type="radio" name="q1" /> 2 <br />
</p>
<p>
<IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><br />
<input type="radio" name="q2" id = "correct2"/> 5 <br />
<input type="radio" name="q2" /> 8 <br />
<input type="radio" name="q2" /> 9 <br />
<input type="radio" name="q2" /> 4 <br />
</p>
<p>
<IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><br />
<input type="radio" name="q3" id = "correct3"/> 10 <br />
<input type="radio" name="q3" /> 8 <br />
<input type="radio" name="q3" /> 4 <br />
<input type="radio" name="q3" /> 5 <br />
</p>
<p>
<IMG SRC=Game\1.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\1.jpg><br />
<input type="radio" name="q4" /> 7 <br />
<input type="radio" name="q4" /> 11 <br />
<input type="radio" name="q4" /> 14 <br />
<input type="radio" name="q4" id = "correct4"/> 15 <br />
</p>
<p>
<input type="button" value="Submit" onClick = "showResult()" />
</p>
</form>
</body>
</html>
and this is the code when i add more than four questions which does not work at all!::
<html>
<head>
<script = "javascript">
document.write('<center><b><font color="#0000FF" font size=18>Binary Quiz</font></b></center>');
document.write("<br clear=all>");
document.write('This quiz is for those with the basic knowledge of Binary numbers, have fun and enjoy!');
document.write("<br clear=all>");
function show_alert()
{
alert("Think - binary, convert decimal numbers into binary first if it helps, for example, 1=?, 2=?, 3=0011");
}
function myResult(){
correctanswers = 0;
if (document.myForm.q1[0].checked) correctanswers++;
if (document.myForm.q2[1].checked) correctanswers++;
if (document.myForm.q3[2].checked) correctanswers++;
if (document.myForm.q4[3].checked) correctanswers++;
if (document.myForm.q5[4].checked) correctanswers++;
if (document.myForm.q5[5].checked) correctanswers++;
if (document.myForm.q5[6].checked) correctanswers++;
if (document.myForm.q5[7].checked) correctanswers++;
if (document.myForm.q9[8].checked) correctanswers++;
if (document.myForm.q10[9].checked) correctanswers++;
if (document.myForm.q11[10].checked) correctanswers++;
if (document.myForm.q12[11].checked) correctanswers++;
document.getElementById("correct1").style.backgroundColor="yellow";
document.getElementById("correct2").style.backgroundColor="yellow";
document.getElementById("correct3").style.backgroundColor="yellow";
document.getElementById("correct4").style.backgroundColor="yellow";
document.getElementById("correct5").style.backgroundColor="yellow";
document.getElementById("correct6").style.backgroundColor="yellow";
document.getElementById("correct7").style.backgroundColor="yellow";
document.getElementById("correct8").style.backgroundColor="yellow";
document.getElementById("correct9").style.backgroundColor="yellow";
document.getElementById("correct10").style.backgroundColor="yellow";
document.getElementById("correct11").style.backgroundColor="yellow";
document.getElementById("correct12").style.backgroundColor="yellow";
return correctanswers;
}
function showResult(){
correctAnswers2 = myResult();
alert("You have answered" + correctAnswers2 + "answers correctly!");
}
</script>
</head>
<body>
<input type="button" onclick="show_alert()" value="Hint" />
<form name="myForm" action="">
<center>
<p>
<IMG SRC=Game\0.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><br />
<input type="radio" name="q1" /> -1 <br />
<input type="radio" name="q1" /> 0 <br />
<input type="radio" name="q1" id = "correct1"/> 1 <br />
<input type="radio" name="q1" /> 2 <br />
</p>
<p>
<IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><br />
<input type="radio" name="q2" id = "correct2"/> 5 <br />
<input type="radio" name="q2" /> 8 <br />
<input type="radio" name="q2" /> 9 <br />
<input type="radio" name="q2" /> 4 <br />
</p>
<p>
<IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><br />
<input type="radio" name="q3" id = "correct3"/> 10 <br />
<input type="radio" name="q3" /> 8 <br />
<input type="radio" name="q3" /> 4 <br />
<input type="radio" name="q3" /> 5 <br />
</p>
<p>
<IMG SRC=Game\1.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\1.jpg><br />
<input type="radio" name="q4" /> 7 <br />
<input type="radio" name="q4" /> 11 <br />
<input type="radio" name="q4" /> 14 <br />
<input type="radio" name="q4" id = "correct4"/> 15 <br />
</p>
<p>
<IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><br />
<input type="radio" name="q5" /> 13 <br />
<input type="radio" name="q5" /> 8 <br />
<input type="radio" name="q5" id = "correct5"/> 9 <br />
<input type="radio" name="q5" /> 5 <br />
</p>
<p>
<IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\1.jpg><br />
<input type="radio" name="q6" /> 10 <br />
<input type="radio" name="q6" id = "correct6"/> 11 <br />
<input type="radio" name="q6" /> 13 <br />
<input type="radio" name="q6" /> 6 <br />
</p>
<p>
<IMG SRC=Game\0.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><br />
<input type="radio" name="q7" /> 3 <br />
<input type="radio" name="q7" id = "correct7"/> 2 <br />
<input type="radio" name="q7" /> 10 <br />
<input type="radio" name="q7" /> 5 <br />
</p>
<p>
<IMG SRC=Game\1.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><br />
<input type="radio" name="q8" /> 11 <br />
<input type="radio" name="q8" /> 14 <br />
<input type="radio" name="q8" /> 12 <br />
<input type="radio" name="q8" id = "correct8"/> 13 <br />
</p>
<p>
<IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\1.jpg><br />
<input type="radio" name="q9" /> 13 <br />
<input type="radio" name="q9" /> 16 <br />
<input type="radio" name="q9" id = "correct9"/> 11 <br />
<input type="radio" name="q9" /> 3 <br />
</p>
<p>
<IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\0.jpg><br />
<input type="radio" name="q10" /> 5 <br />
<input type="radio" name="q10" /> 14 <br />
<input type="radio" name="q10" /> 8 <br />
<input type="radio" name="q10" id = "correct10"/> 4 <br />
</p>
<p>
<IMG SRC=Game\1.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\0.jpg><br />
<input type="radio" name="q11" id = "correct11"/> 12 <br />
<input type="radio" name="q11" /> 11 <br />
<input type="radio" name="q11" /> 1 <br />
<input type="radio" name="q11" /> 2 <br />
</p>
<p>
<IMG SRC=Game\1.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><br />
<input type="radio" name="q12" /> 15 <br />
<input type="radio" name="q12" /> 3 <br />
<input type="radio" name="q12" id = "correct12"/> 14 <br />
<input type="radio" name="q12" /> 10 <br />
</p>
<p>
<input type="button" value="Submit" onClick = "showResult()" />
</p>
</form>
</body>
</html>