开发者

exam with timer in javascript [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I would appreciate it if you can help me with this program. I would like the program to run ike this:

  1. 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.
  2. check if the answer is right or wrong using a promptbox.
  3. 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=开发者_StackOverflow中文版"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

// [question number, answer, question]
var qanda =[ 
[1,15,"Add 11 + 4"],
[2,7,"Add 4 + 3"],
[3,7,"Subtract 9 - 2"]
];


function getQuestion(n){


document.getElementById("disp_question").innerHTML = qanda[n][2];

document.getElementById("intp_div").style.display = "block";

}

function checkAnswer(n){


if(document.getElementById("intp_answer").value != undefined){

if(document.getElementById("intp_answer").value == qanda[n][1]){

alert("correct")

    }else{
   alert("incorrect")
    }

}
}

And you could add this below your retry button

<div id="intp_div" style="display:none">
<h3 id="disp_question"></h3><input id="intp_answer" type="text" value=""><input type="button" value="Submit Answer" onclick="checkAnswer(2)" />
</div>`

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜