I would appreciate it if you can help me with this program. I would like the program to run ike this:
- upon clicking a button, a question like 3 X 2 will be written in the document with a textbox wherein I can put the answer.
- check if the answer is right or wrong using a promptbox.
- It should have a timer that goes from 60 to 0 and when it reaches zero and you weren’t able to answer it, then it will prompt you that the time is up.
I figured out the countdown timer already. I just don’t know how to create the rest ^_^.
it would be great if you can incorporate it with my codes that i have figured. here is my code so far..
<html>
<head>
<title>JavaScript Timer</title>
<script type="text/javascript">
var SECONDS_LEFT, TIMER, TIMES_UP;
function resetTimer(seconds){
SECONDS_LEFT = seconds;
document.Timer.TimeLeft.value = SECONDS_LEFT;
clearTimeout(TIMER);
}
function decrementTimer(){
TIMES_UP = false;
document.Timer.TimeLeft.value = SECONDS_LEFT;
SECONDS_LEFT--;
if (SECONDS_LEFT >= 0) {
TIMER = setTimeout(decrementTimer, 1000);
} else {
alert("Time's up!");
resetTimer(60);
}
}
</script>
</head>
<body onload="resetTimer(60)">
<form name="Timer" onsubmit="return false;">
Timer: <input type="text" name="TimeLeft" size="2"
style="text-align:center" onfocus="this.blur();">
seconds left<br>
<input type="button" name="btnStart"
value="Start Quizz" onclick="decrementTimer();">
<input type="button" name="btnReset"
value="Retry" onclick="resetTimer(60);">
</form>
</body>
</html>
you could store the question and answers in a multidimensional array like follows
And you could add this below your retry button
this it just to hepl you get on your way Note:
onclick="checkAnswer(2)"the “2” is the question your refferencing from the q and a array