www.webdeveloper.com
Results 1 to 3 of 3

Thread: Basic Javascript Countdown question

  1. #1
    Join Date
    Jul 2014
    Posts
    16

    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...

    Thanks!

  2. #2
    Join Date
    Oct 2012
    Location
    Croatia
    Posts
    255
    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
    Location
    localhost
    Posts
    2,411
    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
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

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



Recent Articles