jquery - Implementing timer Javascript - Trivia Game -
this question has answer here:
i've written trivia game in javascript, having hard time understanding how correctly implement timer each question. i've made each question gets presented individually, , i'd have timer each question. if timer runs out, should proceed next question.
here link
jsfiddle
if take few minutes , modify jsfiddle, or let me know i'd have in order make each question count down 10, i'd appreciate it. lot!
timers in javascript work asynchronously. first thing should know. secondly depending on need can use either a:
settimeout(function, timeout)
1 allows delay execution of function provided time provided (in milliseconds).setinterval(function, timer)
1 makes function call everytimer
milliseconds
depending on how intertwine these code should like:
function timerexpired(){ questioncounter++; newquestion(); settimeout(timerexpired, 15000); } //this 1 make sure every 15 seconds, questions "moved on" next question. can same interval, so: setinterval(function(){ questioncounter++; newquestion(); }, 15000);
this far can go without turning me writting code.
Comments
Post a Comment