Title: Timer
Last modified: March 20, 2020

---

# Timer

 *  Resolved [jarman22](https://wordpress.org/support/users/jarman22/)
 * (@jarman22)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/timer-21/)
 * Hi
 * I see there is a timer for the quiz as a whole, is there any way it can be done
   per question? Like 10/15 seconds per question?
 * Just thinking how to prevent cheating.
 * Thanks

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/timer-21/page/2/?output_format=md) [→](https://wordpress.org/support/topic/timer-21/page/2/?output_format=md)

 *  Plugin Author [Harmonic Design](https://wordpress.org/support/users/harmonic_design/)
 * (@harmonic_design)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/timer-21/#post-12566746)
 * Hi again jarman22,
    this is not something built into HD Quiz, but this should
   be fairly simple to add in. When I have some spare time over the weekend I’ll
   see about writing a simple function that you can add to your theme’s `functions.
   php` file that will extend HD Quiz do this.
 *  Thread Starter [jarman22](https://wordpress.org/support/users/jarman22/)
 * (@jarman22)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/timer-21/#post-12567633)
 * I very much appreciate it, obviously whenever you do have some spare time, please
   don’t go out if your way if there are more important things to be doing.
 * Have a great weekend.
 *  Plugin Author [Harmonic Design](https://wordpress.org/support/users/harmonic_design/)
 * (@harmonic_design)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/timer-21/#post-12570630)
 * Check this out!
 * In the below script, you will see a line `const hdq_time_per_question = 25;`
   
   Change the `25` to however many seconds you want to give a user to select a question.
   If they do not answer within this time frame, then HD Quiz will auto go to the
   next question.
 * NOTE: This will ONLY work if you are using the primary pagination method built
   into every question – like most things, this is NOT compatible with WP Pagination.
   So if you are using WP Pagination, please remove it and just use teh pagination
   option built into each question.
 *     ```
       function hdq_per_question_timer()
       { ?>
       	<div id = "hdq_per_question_timer" style = "position: fixed; bottom: 1rem; right: 1rem; padding: 1rem; background:#eee;"></div>
       	<script>
       		const hdq_timer_el = document.getElementById("hdq_per_question_timer");
       		const hdq_time_per_question = 25;
       		function hdq_per_question_timer(){			
       			let time_left = hdq_time_per_question;
       			let timems = hdq_time_per_question * 1000; // convert seconds to ms
       			let timer = setInterval(function(){				
       				if(time_left < 0){
       					time_out_next_question();
       				} else {					
       					hdq_timer_el.innerHTML = time_left;
       				}
       				time_left = time_left - 1;
       			}, 1000);
   
       			function time_out_next_question(){
       				if(jQuery(".hdq_next_button:visible")[0]){
       					jQuery(".hdq_next_button:visible").click();
       				} else {
       					jQuery(".hdq_finsh_button:visible").click();
       					clearInterval(timer);
       					hdq_timer_el.remove();
       				}
       				time_left = hdq_time_per_question;
       			}
   
       			// reset timer if an answer has been selected
       			jQuery(".hdq_label_answer").on("click", function(){
       				time_out_next_question(); // we want to auto goto the next question
       			})
       		}
       		hdq_per_question_timer();
       	</script>
       <?php }
       add_action("hdq_after", "hdq_per_question_timer");
       ```
   
 *  Thread Starter [jarman22](https://wordpress.org/support/users/jarman22/)
 * (@jarman22)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/timer-21/#post-12571598)
 * Thank you, I will give this a go! Appreciate your quick response and doing this
   over the weekend!
 *  Thread Starter [jarman22](https://wordpress.org/support/users/jarman22/)
 * (@jarman22)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/timer-21/#post-12571703)
 * Hi
 * Sorry to bother you, the timer works brilliantly but I noticed that should the“
   Next” button is clicked manually, the timer is still counting down during the
   next question.
 * I have disable the WP Pagination and have Paginated per question as you mentioned,
   works a treat but not sure why the timer is still counting down when you press“
   Next”.
 * Confused!
 *  Plugin Author [Harmonic Design](https://wordpress.org/support/users/harmonic_design/)
 * (@harmonic_design)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/timer-21/#post-12571721)
 * Ah good catch! I overlooked that. I’ll have to edit the code and resend.
 * I’ll make it so that if a user selects next without actually answering anything,
   the timer will restart for the new question as well.
 *  Plugin Author [Harmonic Design](https://wordpress.org/support/users/harmonic_design/)
 * (@harmonic_design)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/timer-21/#post-12571950)
 * Here is teh updated code that looks for if the user selects the next or finish
   button as well!
 *     ```
       function hdq_per_question_timer()
       { ?>
       	<div id = "hdq_per_question_timer" style = "position: fixed; bottom: 1rem; right: 1rem; padding: 1rem; background:#eee;"></div>
       	<script>
       		const hdq_timer_el = document.getElementById("hdq_per_question_timer");
       		const hdq_time_per_question = 25;
       		function hdq_per_question_timer(){			
       			let time_left = hdq_time_per_question;
       			let timems = hdq_time_per_question * 1000; // convert seconds to ms
       			let timer = setInterval(function(){				
       				if(time_left < 0){
       					time_out_next_question();
       				} else {					
       					hdq_timer_el.innerHTML = time_left;
       				}
       				time_left = time_left - 1;
       			}, 1000);
   
       			function time_out_next_question(){
       				if(jQuery(".hdq_next_button:visible")[0]){
       					jQuery(".hdq_next_button:visible").click();
       				} else {
       					jQuery(".hdq_finsh_button:visible").click();
       					clearInterval(timer);
       					hdq_timer_el.remove();
       				}
       				time_left = hdq_time_per_question;
       			}
   
       			// reset timer if an answer has been selected
       			jQuery(".hdq_label_answer").on("click", function(){
       				time_out_next_question(); // we want to auto goto the next question
       			});
   
       			jQuery(".hdq_next_button").on("click", function(){
       				time_left = hdq_time_per_question;
       			});
   
       			jQuery(".hdq_finsh_button").on("click", function(){
       					clearInterval(timer);
       					hdq_timer_el.remove();
       			});				
       		}
       		hdq_per_question_timer();
       	</script>
       <?php }
       add_action("hdq_after", "hdq_per_question_timer");
       ```
   
 *  Thread Starter [jarman22](https://wordpress.org/support/users/jarman22/)
 * (@jarman22)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/timer-21/#post-12572605)
 * Hi
 * Thanks for doing this late last night!
 * It seems now that each time I click on “Next”, it skips the next question and
   go straight to the following one.
 * So at Question 1. I’ll tick the answer I think is right, click on “Next”, it 
   skips Question 2. straight to Question 3. Again, I’ll answer this one click “
   Next” it goes to Question 5. skipping the 4th.
 * Any idea on what I could be doing wrong?
 * Thanks
 *  Plugin Author [Harmonic Design](https://wordpress.org/support/users/harmonic_design/)
 * (@harmonic_design)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/timer-21/#post-12575173)
 * Can you please send me a link to a quiz? I’m not able to replicate this issue
   on my side.
 * For me, if I am on Question #1 and either select and answer or select the next
   button, we automatically go to Question #2
 *  Thread Starter [jarman22](https://wordpress.org/support/users/jarman22/)
 * (@jarman22)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/timer-21/#post-12575279)
 * Sure
 * Here’s the link:- [https://jarbinator.com/quiz/music/](https://jarbinator.com/quiz/music/)
 * I think the timer is working now, not sure what happened this morning. I’ve noticed
   that the timer starts even before question 1 comes up. Also I noticed that when
   the quiz is finished, it shows the correct and wrong answers apart from the last
   Question where it doesn’t show either.
 *  Plugin Author [Harmonic Design](https://wordpress.org/support/users/harmonic_design/)
 * (@harmonic_design)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/timer-21/#post-12575433)
 * Do not enable pagination on the first question.
 * Pagination basically means “start a new page with this question”. This is why
   you have to press “next” to see the first question.
 *  Thread Starter [jarman22](https://wordpress.org/support/users/jarman22/)
 * (@jarman22)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/timer-21/#post-12575473)
 * ok, I’ve removed pagination for the 1st Question. I’m still not getting the last
   question to work, so if I select the right answers for 15 Questions, it shows
   14/15 correct. Any ideas? Sorry 🙁
 *  Plugin Author [Harmonic Design](https://wordpress.org/support/users/harmonic_design/)
 * (@harmonic_design)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/timer-21/#post-12575482)
 * I’m pretty sure that it’s just a bug with the question timer. I’ll look into 
   it and let you know asap 🙂
 *  Plugin Author [Harmonic Design](https://wordpress.org/support/users/harmonic_design/)
 * (@harmonic_design)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/timer-21/#post-12575741)
 * Heeeeeerrrreeee we go. Think I got it working again now.
 *     ```
       function hdq_per_question_timer()
       { ?>
       	<div id = "hdq_per_question_timer" style = "position: fixed; bottom: 1rem; right: 1rem; padding: 1rem; background:#eee;"></div>
       	<script>
       		const hdq_timer_el = document.getElementById("hdq_per_question_timer");
       		const hdq_time_per_question = 25;
       		function hdq_per_question_timer() {
       			let time_left = hdq_time_per_question;
       			let timems = hdq_time_per_question * 1000; // convert seconds to ms
       			let timer = setInterval(function() {
       				if (time_left < 0) {
       					time_out_next_question();
       				} else {
       					hdq_timer_el.innerHTML = time_left;
       				}
       				time_left = time_left - 1;
       			}, 1000);
   
       			function time_out_next_question() {
       				if (jQuery(".hdq_next_button:visible")[0]) {
       					jQuery(".hdq_next_button:visible").click();
       				} else {
       					clearInterval(timer);
       					hdq_timer_el.remove();
       					setTimeout(function() {
       						jQuery(".hdq_finsh_button").click();
       					}, 500);
       				}
       				time_left = hdq_time_per_question;
       			}
   
       			// reset timer if an answer has been selected
       			jQuery(".hdq_label_answer").on("click", function() {
       				time_out_next_question(); // we want to auto goto the next question
       			});
   
       			jQuery(".hdq_next_button").on("click", function() {
       				time_left = hdq_time_per_question;
       			});
   
       			jQuery(".hdq_finsh_button").on("click", function() {
       				clearInterval(timer);
       				hdq_timer_el.remove();
       			});
       		}
       		hdq_per_question_timer();
       	</script>
       <?php }
       add_action("hdq_after", "hdq_per_question_timer");
       ```
   
 *  Thread Starter [jarman22](https://wordpress.org/support/users/jarman22/)
 * (@jarman22)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/timer-21/#post-12575764)
 * Yes! What a great job! I can’t thank you enough and really appreciate your help
   over the last few days it hadn’t gone unnoticed.
 * I certainly would recommend your work highly.
 * I’ll look forward to seeing some more of your new features in future!
 * Would be good (if you haven’t already) have like a update post or something to
   inform us of the possible new plugin etc.
 * Thanks again!

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/timer-21/page/2/?output_format=md) [→](https://wordpress.org/support/topic/timer-21/page/2/?output_format=md)

The topic ‘Timer’ is closed to new replies.

 * ![](https://ps.w.org/hd-quiz/assets/icon-256X256.gif?rev=2936040)
 * [HD Quiz](https://wordpress.org/plugins/hd-quiz/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/hd-quiz/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/hd-quiz/)
 * [Active Topics](https://wordpress.org/support/plugin/hd-quiz/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/hd-quiz/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/hd-quiz/reviews/)

 * 16 replies
 * 2 participants
 * Last reply from: [Harmonic Design](https://wordpress.org/support/users/harmonic_design/)
 * Last activity: [6 years ago](https://wordpress.org/support/topic/timer-21/page/2/#post-12817159)
 * Status: resolved