ga-wdi-exercises / project1

[project] GA- Project 1
3 stars 75 forks source link

issue with timer not displaying and counting too fast #260

Closed alpha2262 closed 8 years ago

alpha2262 commented 8 years ago

I tried jquery to update html on page. First issue: I expected minutes and seconds time elapse to appear to happen. No content displayed happened instead.

Second issue: the timer appears to be counting faster with each successive click, which I recall discussing as an issue in class but can't remember how to fix. Timer is accumulating time faster than second intervals is happening instead.

My repo link is https://github.com/alpha2262/concentration/blob/silver/javascript.js and my question is about lines 72 - 88.

jshawl commented 8 years ago

second issue: you need to clear the timeout when you click, using clearTimeout

RobertAKARobin commented 8 years ago

You could also detect whether there's already a timer. On click, before you setTimeout or setInterval, check whether timerIsAlreadyRunning == false, and only set the timer if it's false. Then, after setting the timer, timerIsAlreadyRunning = true.

RobertAKARobin commented 8 years ago

In pseudocode:

set timerIsAlreadyRunning to false

on click
    if timerIsAlreadyRunning is false, then
        setTimeout
        set timerIsAlreadyRunning to true
    otherwise do nothing