javascript - Setting Timer For Online Quiz -
javascript - Setting Timer For Online Quiz -
i'm trying build online quiz, i've done of - questions selected randomly database 1 @ time, user enters/selects answer, there response, random question pops - i've done that, tricky aspect how attach timer(javascript, guess) instance question pops , when response entered...any general guideline on how this?
thanks.
i give approach on how go creating timer of sorts every question. prefer using javascript timer employing setinterval()
method because it's pretty easy implement. i've given sample snippet starts counting 0 every second. can modify countdown timer suit needs. relevant documentation on timing events in js.
class="snippet-code-js lang-js prettyprint-override">var myvar = setinterval(function() { mytimer() }, 1000); var d = 0; function mytimer() { document.getelementbyid("demo").innerhtml = d++; }
class="snippet-code-html lang-html prettyprint-override"><!doctype html> <html> <body> <p>a script on page starts timer:</p> <p id="demo"></p> </body> </html>
a thing maintain in mind while developing javascript timer business relationship browser refreshes. want maintain tabs on 'state' of timer if user accidently hits refresh or loses net connectivity. if using javascript, might want seek local storage built browser storing value. @ point in time have this:
// store localstorage.setitem("lasttime", d); //in context of code snippet // retrieve var lasttime = localstorage.getitem("lasttime");
so can maintain track of accidental glitches while attempting question , correctly business relationship total time question. can save these times per question database or create request php
script necessary compiling , reporting of whole quiz 1 time again largely depends on implementation.
if want implement whole thing in php, might want check out using cookies or session variables storing time elapsed per question specific user.
i hope gets started in right direction.
javascript php timer
Comments
Post a Comment