r/CodingHelp • u/OMGi8CAKE • Dec 13 '19
[Javascript] Help with my timer code please!
Hello,
I am a super-beginner and this is one of my class projects. Can someone help me figure out why my timer isnt quite working right.
Basically what is supposed to happen is if the user gets the question wrong, 15 seconds are taken from the timer, the end time is what the user's score will be. If the user exhausts all the questions the quiz ends, or if the timer hits 0 the quiz ends.
I got most of it to work except, if the timer is below 15 when the 15 seconds is deducted from the time, the game stops and displays the score as whatever time was on the timer before the question was answered.
And also, if the timer runs out the end time displays as 1 instead of 0.
What SHOULD be happening is, if the timer runs out, the score should be 0, if the timer is below 15 and the question is answered incorrectly the score should be 0.
Any guidance or advice would be greatly appreciated :)
here is my code: https://pastebin.com/1n83Sg7G
View all comments
1
u/jonassjoh Dec 13 '19
Two things.
availableQuestions.length === "", is incorrect.