Results 1 to 3 of 3

Thread: Basic Javascript Countdown question

Hybrid View

  1. #1
    Join Date
    Jul 2014

    Basic Javascript Countdown question

    Hi everyone,

    I'm in the process of learning Javascript and my assignment is to build a Javascript countdown timer. The script should accept an initial integer amount of seconds in the window (for example, "116"), count it down to 0, and stop upon reaching this value. Only the amount of seconds to countdown should be displayed (no milliseconds). I need a Start, Stop and Reset button as well.

    I figured out how to build a stopwatch but this I can't figure out - any have any live examples to demonstrate? I am stuck on the custom integer that the user can enter...


  2. #2
    Join Date
    Oct 2012
    To get the custom integer from the user you can use the prompt box, input tag... anything user can interact with and set, choose... a value. Use the setInterval function to run a custom function (which will do the job) every second (that is 1000 ms).

    Implementing the Reset button is fairly easy. Let's say you choose a h1 tag as a display. When user clicks the Reset button simply set h1's value to 0.
    To stop the countdown you should connect your Stop button with the JavaScript function which will use the clearInterval function to clear any set interval and cancel the countdown.

  3. #3
    Join Date
    Mar 2007
    You will find plenty of examples on the internet, not being rude but this sounds homeworky type question, something that crops up regular, stopwatch / count down timer, dice roll and other scripts that are designed to test coders skills.

    So, try looking for something that does what you need and modify it so that you know what is happening so that when asked, you can explain how it functions.

    Good Luck
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center