Hi
I’m having a little problem getting my scoring system to work in my javascript maths game. After the person has finished answering all questions, they should get all their answers and show whether they are correct or not. I have got this part working, but the scoring system is not showing, so the person cannot see their score at the end. A section of my code is shown below:
[CODE]
<html>
<head>
<title>Mathematics Quiz</title>
<link rel=”stylesheet” type=”text/css” href=”quiz.css”>
<script type=”text/javascript”>
quest1 = Math.floor(Math.random()*101);
quest2 = Math.floor(Math.random()*101);
quest3 = Math.floor(Math.random()*101);
quest4 = Math.floor(Math.random()*101);
var question1 = prompt(quest1+ “+” +quest2);
var question2 = prompt(quest3+ “+” +quest4);
</script>
</head>
<body>
<h1>Mathematics Quiz</h1>
<script type=”text/javascript”>
score = 0;
if (question1 == quest1+quest2)
{
document.write (‘<p class=”correct”>’+ quest1+’+’+quest2 +’= ‘+ question1 + ‘ …Well Done!</p>’);
score++;
score++;
}
else
{
document.write (‘<p class=”incorrect”>’+quest1+’+’+quest2 +’= ‘+ question1+ ‘ …Oh dear!, The correct answer is ‘+ (quest1 + quest2)+ ‘</p>’);
}
if (question2 == quest3+quest4)
{
document.write (‘<p class=”correct”>’+quest3+’+’+quest4 +’= ‘+ question2+ ‘ …Well Done!</p>’);
score++;
score++;
}
else
{
document.write (‘<p class=”wrong”>’+quest3+’+’+quest4 +’= ‘+ question2+ ‘ …Oh Dear!, The correct answer is ‘ + (quest3 + quest4)+ ‘</p>’);
}
if (score == 4)
{
document.write (‘<p class=”fourm”>you scored: ‘+ score+ ‘</p>’);
document.bgColor=”gold”;
}
if (score == 2)
{
document.write (‘<p class=”twom”>you scored: ‘+ score+ ‘</p>’);
document.bgColor=”silver”;
}
if (score == 0)
{
document.write (‘<p class=”zerom”>you scored: ‘+ score+ ‘</p>’);
document.bgColor=”darkred”;
}
</script>
</body>
</html>
Can you tell me what is going wrong and how I correct this so the person can see what they have scored?
Thanks in advance