We have answer of your question!

100% solved queries, no empty question

Question: Start time once game is complete




<div id="content">
    <input type=button value="Start Game" id=sGame class=sGame />
    Timer: <input type=text class=timer id=timer value="" READONLY />

    <div id="cardPile"> </div>
    <div id="cardSlots"> </div>
    <div id="successMessage">
        <h2>You did it in <span class="time"></span> seconds!</h2>
        <button onclick="init()">Play Again</button>

The issue I am having is once the PLAY AGAIN button is clicked the timer is not restarting from 0. I tried the following code


inside the


function, but the timer starts off even before the Start Game button is clicked.

Question author Si8 | Source



if (timer !== null) clearInterval(timer), value = 0;

If the timer is NOT null (it's running) -> clear the interval, set the value variable to 0, then restart the interval.

$('#sGame').click(function () {
    if (timer !== null) clearInterval(timer), value = 0;
    timer = setInterval(function () {
        value = value + 1;
    }, interval);
Answer author Pmandell

Tickanswer.com is providing the only single recommended solution of the question Start time once game is complete under the categories i.e jquery , html , . Our team of experts filter the best solution for you.

Related Search Queries:

You may also add your answer

Thanks for contributing an answer to Tick Answer!