/    Sign up×
Community /Pin to ProfileBookmark

setting a timer for a javascript quiz

Hi

I am creating a quiz using javascript which uses prompts and I am having a little difficulty setting atime limit for a user to answe each question. An example of some of my code is below:

[CODE]
<html>
<head>
<title>Quiz</title>
<script language=”JavaScript”>
setTimeout(“Times Up!”,60000);
alert(“You are about to play a multiple choice quiz game.nPlease answer a,b,c or d nYou have one minute to finish the quiznClick OK to play”)
var count= 0;
var quest1=prompt(“Question 1: What does goku turn into?nA) Supersaiyan.nB) namekien.nC) Yardratian.nD) Giant Ape.”);
var quest2=prompt(“Question 2: What is vegeta’s home planet callednA) Saiyan.nB) VegetanC) Namek.nD) Ovatronpercyi8″);
</script>
</head>
<body>
<h1>Comics 4 U – Multiple Choice Quiz</h1>
<h3> Your answers were…</h3>
<script type=”text/javascript”>

if ((quest1 == “a”) || (quest1 == “A”))
{
document.write(“Question 1 … What does goku turn into? <font color=’green’>” + quest1 + “)Supersaiyan.</font> is … CORRECT!!!!!!!!!!<br /><br />”);
count += 2;
}
else
{
document.write(“Question 1 … What does goku turn into? <font color=’red’>” + quest1 + “</font> is … WRONG!!!!!!!!!<br />The correct answer is <font color=’blue’>A) Supersaiyan.</font>.<br /><br />”);
count -= 1;
}
if ((quest2 == “b”) || (quest2 == “B”))
{
document.write(“Question 2: What is vegetas home planed called? <font color=’blue’>” + quest2 + “) vegeta.</font> is … CORRECT!!!!!!!!!!<br /><br />”);
count += 2;
}
else
{
document.write(“Question 2: What is vegetas home planet called? <font color=’red’>” + quest2 + “</font> is … WRONG!!!!!!!!!<br />The correct answer is <font color=’blue’>B) vegeta.</font>.<br /><br />”);
count -= 1;
}
document.write(“Your score is <font color=’blue’>” + count + “</font> out of 20!”);
if (count == 20)
{
document.write(“<br /><br />Congratulations you got them all right!!!”);
}
else
if ((count > 12) && (count < 20))
{
document.write(“<br /><br />You were close to getting them all right…Well done!!!”)
}
else
{
document.write(“<br /><br />Better luck next time…”);
}
</script>
</body>
</html>
[/CODE]

Cna you please tell me where I am going wrong and how to create the timer for a time limit of 1 minute for each question?

Thanks if you can help.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisApr 22.2009 — Your fatal error is using document.write(). It doesn't matter what you do in the document if you keep wiping it out with document.write() statements.
×

Success!

Help @rushhour2 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...