Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8286527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:47:58+00:00 2026-06-08T11:47:58+00:00

I am working on a simple game right now. its almost done except for

  • 0

I am working on a simple game right now. its almost done except for the timer has a glitch in it and I can’t figure out whats doing it. when you push a button, an HTML5 text on the canvas starts to count down from 35 to 0. On the first run it’s fine. But if you choose to play again with out refresh the timer starts to countdown faster. here is the code.

var timer = 35;

ctx.fillText("Countdown: " + timer, 320, 32);

function resetReggie(){
    reggie.x = canvasWidth / 2;
    reggie.y = canvasHeight / 2;
}

//Starts Timer for Timed Game
function timedMsg()
{
    resetReggie();
    ballsCaught = 0;
    timer = 35;
    alert('Pick up as many as you can in ' + timer + ' seconds');
    countDown();
        var t=setTimeout(function() {
        var again = confirm("TIMES UP! You Gathered " + ballsCaught + " Balls! Play Again?");
            if (again === true){ 
                timedMsg(); 
                resetReggie(); 
            }
                if (again === false){
                resetReggie();
                ballsCaught = 0;
                timer = 35;
                }
        }, timer * 1000);

}

function countDown() {
    if (timer != 0){
        timer-=1;
        setTimeout('countDown()', 1000);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T11:48:00+00:00Added an answer on June 8, 2026 at 11:48 am

    I think the problem is in the line

        }, timer * 1000);
    

    where you have a value that is at most 34 at the time ‘timer’ is evaluated to set the timeout. Because you initialize it to 35 but then call countDown() which decreases it to 34, then you have a call to confirm() which might let ‘timer’ decrease even more. As a result the subsequent call to timedMsg() happens a little too soon causing countDown() to be called twice as often. Try the following (I ran it in node) and then change the 4 to 6.

    function countDown() {
        console.log("Countdown: " + timer, 320, 32);
        if (timer != 0) {
            timer -= 1;
            setTimeout(countDown, 1000);
        }
    }
    function timedMsg() {
        timer = 5;
        countDown();
        var t=setTimeout(function() {
            timedMsg();
        }, 4 * 1000);
    }
    timedMsg();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a simple 2D Real time strategy game using XNA. Right now
I'm building an open source 2D game engine called YoghurtGum. Right now I'm working
So, recently, I've been working on a JS/HTML5 Game Engine. Right now I'm calling
I am working on a simple platform game in HTML5/Canvas/Javascript/jQuery. You can see it
I'm working on a prototype for a shmup game in C++ using SDL...Right now
im working on a simple game like space invaders,and i got into a problem.
I'm working on a simple board game in qt, and i have some problem
I'm trying to make a simple text editor with winapi, its working for simple
Working on a simple TimeTracker App. You start a timer, wait a certain time,
I'm new to android game development. I currently working on a simple android app

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.