joanmicham
09-30-2012, 02:43 AM
Hello i have an assignment about creating a quiz in javascript which will display the score at the end and then an alert with the wrong answers. I have this code but i don't know what is going wrong. Can you help me please?
<html>
<head>
<title>Ioanna Michael - Personal Portfolio</title>
<link rel="stylesheet" type="text/css" href="im.michael.css" />
<script>
var totalquestions=4;
var actualchoices=new Array()
var correctchoices=new Array()
correctchoices[0]='b'
correctchoices[1]='c'
correctchoices[2]='b'
correctchoices[3]='c'
function getScore(){
var incorrect=null
for (i=1;i<=totalquestions;i++){
var thequestion=eval("document.immichael.question"+i)
for (j=0;j<thequestion.length;j++){
if (thequestion[j].checked==true)
actualchoices[i]=thequestion[j].value
}
if (actualchoices[i]!=correctchoices[i]){
if (incorrect==null)
incorrect=i
else
incorrect+="/"+i
}
}
}
</script>
</head>
<body>
<div id="table">
<table width="1000px" border="0">
<tr>
<th colspan="2"><img src="header.jpg" width="1000px"/></th>
</tr>
<tr>
<td class="menu">
<p><a href="http://www.youtube.com/watch?v=EAfaIAnSOjc&feature=player_embedded">3d Modelling</a></p>
<p><a href="http://www.youtube.com/watch?v=uEvOuhefOks">Video Production</a></p>
<p><a href="http://www.facebook.com/ioanna.michael1">Contact Us</a></p>
<div id="info">
<p style="color:white;"><img src="facebook_logo_2.jpg" width="20px"/> ioanna.michael1</p>
<p style="color:white;"><img src="phone-rotary-symbol.png" width="20px"/> 96 844741</p>
</div>
</td>
<td>
<div id="quiz">
<form method="POST" name="immichael">
<h2><b>Quiz</b></h2>
<ol>
<li>Ti simainei CSS?</li>
<ul>
<li><input type="radio" name="css" value="a">Colourful Style Symbols</input></li>
<li><input type="radio" name="css" value="b">Cascading Style Sheets</input></li>
<li><input type="radio" name="css" value="c">Computer Style Symbols</input></li>
</ul>
<li>Ti simainei HTML?</li>
<ul>
<li><input type="radio" name="html" value="a">Hypno-tic markup language</input></li>
<li><input type="radio" name="html" value="b">Hyper-text mathematical language</input></li>
<li><input type="radio" name="html" value="c">Hyper-text markup language</input></li>
</ul>
<li>Me poia etiketa eisagoume ena senario Javascript?</li>
<ul>
<li><input type="radio" name="java" value="a"><form></form></input></li>
<li><input type="radio" name="java" value="b"> <script></script></input></li>
<li><input type="radio" name="java" value="c"><javascript><javascript></input></li>
</ul>
<li>Me poia entoli orizoume mia sinartisi?</li>
<ul>
<li><input type="radio" name="function" value="a">Script</input></li>
<li><input type="radio" name="function" value="b">Program</input></li>
<li><input type="radio" name="function" value="c">Function</input></li>
</ul>
</ol>
<button onClick="reset()">Clear Answers</button>
</form>
<input type="button" value="Get Score" name="score" onClick="getScore()"/>
<p>Score=<input type="text" name="sc"/></p>
<form method="POST">
<script>
var wrong=0
for (e=0;e<=2;e++)
document.result[e].value=""
var results=document.cookie.split(";")
for (n=0;n<=results.length-1;n++){
if (results[n].charAt(1)=='sc')
parse=n
}
var incorrect=results[parse].split("=")
incorrect=incorrect[1].split("/")
if (incorrect[incorrect.length-1]=='b')
incorrect=""
document.result[0].value=totalquestions-incorrect.length+" out of "+totalquestions
document.result[2].value=(totalquestions-incorrect.length)/totalquestions*100+"%"
for (temp=0;temp<incorrect.length;temp++)
document.result[1].value+=incorrect[temp]+", "
</script>
</form>
</div>
</td>
</tr>
<tr>
<td>
</td>
<td>
</br>
<p><iframe width="700" height="400" src="http://www.youtube.com/embed/-HO27zsX3Bw?feature=player_embedded" frameborder="0" allowfullscreen></iframe></p>
</td>
</tr>
<tr>
<td class="footer"><th colspan="2">Ioanna Michael Copyrights 2012</th></td>
</tr>
</table>
</div>
</body>
</html>
<html>
<head>
<title>Ioanna Michael - Personal Portfolio</title>
<link rel="stylesheet" type="text/css" href="im.michael.css" />
<script>
var totalquestions=4;
var actualchoices=new Array()
var correctchoices=new Array()
correctchoices[0]='b'
correctchoices[1]='c'
correctchoices[2]='b'
correctchoices[3]='c'
function getScore(){
var incorrect=null
for (i=1;i<=totalquestions;i++){
var thequestion=eval("document.immichael.question"+i)
for (j=0;j<thequestion.length;j++){
if (thequestion[j].checked==true)
actualchoices[i]=thequestion[j].value
}
if (actualchoices[i]!=correctchoices[i]){
if (incorrect==null)
incorrect=i
else
incorrect+="/"+i
}
}
}
</script>
</head>
<body>
<div id="table">
<table width="1000px" border="0">
<tr>
<th colspan="2"><img src="header.jpg" width="1000px"/></th>
</tr>
<tr>
<td class="menu">
<p><a href="http://www.youtube.com/watch?v=EAfaIAnSOjc&feature=player_embedded">3d Modelling</a></p>
<p><a href="http://www.youtube.com/watch?v=uEvOuhefOks">Video Production</a></p>
<p><a href="http://www.facebook.com/ioanna.michael1">Contact Us</a></p>
<div id="info">
<p style="color:white;"><img src="facebook_logo_2.jpg" width="20px"/> ioanna.michael1</p>
<p style="color:white;"><img src="phone-rotary-symbol.png" width="20px"/> 96 844741</p>
</div>
</td>
<td>
<div id="quiz">
<form method="POST" name="immichael">
<h2><b>Quiz</b></h2>
<ol>
<li>Ti simainei CSS?</li>
<ul>
<li><input type="radio" name="css" value="a">Colourful Style Symbols</input></li>
<li><input type="radio" name="css" value="b">Cascading Style Sheets</input></li>
<li><input type="radio" name="css" value="c">Computer Style Symbols</input></li>
</ul>
<li>Ti simainei HTML?</li>
<ul>
<li><input type="radio" name="html" value="a">Hypno-tic markup language</input></li>
<li><input type="radio" name="html" value="b">Hyper-text mathematical language</input></li>
<li><input type="radio" name="html" value="c">Hyper-text markup language</input></li>
</ul>
<li>Me poia etiketa eisagoume ena senario Javascript?</li>
<ul>
<li><input type="radio" name="java" value="a"><form></form></input></li>
<li><input type="radio" name="java" value="b"> <script></script></input></li>
<li><input type="radio" name="java" value="c"><javascript><javascript></input></li>
</ul>
<li>Me poia entoli orizoume mia sinartisi?</li>
<ul>
<li><input type="radio" name="function" value="a">Script</input></li>
<li><input type="radio" name="function" value="b">Program</input></li>
<li><input type="radio" name="function" value="c">Function</input></li>
</ul>
</ol>
<button onClick="reset()">Clear Answers</button>
</form>
<input type="button" value="Get Score" name="score" onClick="getScore()"/>
<p>Score=<input type="text" name="sc"/></p>
<form method="POST">
<script>
var wrong=0
for (e=0;e<=2;e++)
document.result[e].value=""
var results=document.cookie.split(";")
for (n=0;n<=results.length-1;n++){
if (results[n].charAt(1)=='sc')
parse=n
}
var incorrect=results[parse].split("=")
incorrect=incorrect[1].split("/")
if (incorrect[incorrect.length-1]=='b')
incorrect=""
document.result[0].value=totalquestions-incorrect.length+" out of "+totalquestions
document.result[2].value=(totalquestions-incorrect.length)/totalquestions*100+"%"
for (temp=0;temp<incorrect.length;temp++)
document.result[1].value+=incorrect[temp]+", "
</script>
</form>
</div>
</td>
</tr>
<tr>
<td>
</td>
<td>
</br>
<p><iframe width="700" height="400" src="http://www.youtube.com/embed/-HO27zsX3Bw?feature=player_embedded" frameborder="0" allowfullscreen></iframe></p>
</td>
</tr>
<tr>
<td class="footer"><th colspan="2">Ioanna Michael Copyrights 2012</th></td>
</tr>
</table>
</div>
</body>
</html>