• We just launched and are currently in beta. Join us as we build and grow the community.

Timer using JavaScript

IPBANNED

Gas Fee Optimizer
I Rep
0
0
0
Rep
0
I Vouches
0
0
0
Vouches
0
Posts
64
Likes
73
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 500 XP
This is a simple Timer using JavaScript. This program has the capability to pause the time and to resume the timer again. It has also one button for the reset function, that the user clicks this button to automatically set the timer begin to zero.

Creating the two buttons for the timer and for displaying the time as you can see in the image below.
1_136.png

This is the source code of the image above.
  1. <div

    id

    =

    "container"

    >
  2. <p

    id

    =

    "output"

    ></

    p

    >
  3. <div

    id

    =

    "controls"

    >
  4. <button

    class

    =

    "button"

    id

    =

    "startPause"

    onClick

    =

    "startPause()"

    >

    Start</

    button

    >
  5. <br

    /

    >
  6. <br

    /

    >
  7. <button

    class

    =

    "button1"

    onClick

    =

    "reset()"

    >

    Reset</

    button

    >
  8. </

    div

    >
  9. </

    div

    >

Here's the source code for the design.
  1. /* CSS Document */
  2. body {
  3. background-color

    :

    #FFF

    ;
  4. }
  5. #container

    {
  6. background

    :

    azure

    ;
  7. width

    :

    500px

    ;
  8. border

    :

    2px

    solid

    blue

    ;
  9. margin

    :

    50px

    auto

    ;
  10. padding

    :

    25px

    ;
  11. overflow

    :

    hidden

    ;
  12. }

  13. #output

    {
  14. background

    :

    azure

    ;
  15. width

    :

    150px

    ;
  16. height

    :

    40px

    ;
  17. margin

    :

    30px

    auto

    ;
  18. font-size

    :

    22px

    ;
  19. font-family

    :

    Verdana,

    Geneva,

    sans-serif

    ;
  20. text-align

    :

    center

    ;
  21. color

    :

    #E60000

    ;
  22. border

    :

    3px

    solid

    blue

    ;
  23. font-weight

    :

    bold

    ;
  24. }
  25. #controls

    {
  26. width

    :

    150

    ;
  27. margin

    :

    5px

    auto

    ;
  28. }

  29. .button

    {
  30. width

    :

    70px

    ;
  31. font-size

    :

    20px

    ;
  32. background

    :

    azure

    ;
  33. border

    :

    2px

    solid

    blue

    ;
  34. border-radius

    :

    8px

    ;
  35. color

    :

    blue

    ;
  36. padding

    :

    5px

    ;
  37. width

    :

    150px

    ;
  38. }
  39. .button1

    {
  40. width

    :

    70px

    ;
  41. font-size

    :

    20px

    ;
  42. background

    :

    azure

    ;
  43. border

    :

    2px

    solid

    red

    ;
  44. border-radius

    :

    8px

    ;
  45. color

    :

    red

    ;
  46. padding

    :

    5px

    ;
  47. width

    :

    150px

    ;
  48. }
  49. .button

    :

    hover

    {
  50. background

    :

    blue

    ;
  51. color

    :

    white

    ;
  52. cursor

    :

    pointer

    ;
  53. }
  54. .button1

    :

    hover

    {
  55. background

    :

    red

    ;
  56. color

    :

    white

    ;
  57. cursor

    :

    pointer

    ;
  58. }

The complete source code.

  1. <!DOCTYPE html>

    <html

    >
  2. <head

    >
  3. <title

    >

    Stopwatch/Timer</

    title

    >
  4. <link

    href

    =

    "css/style.css"

    rel

    =

    "stylesheet"

    type

    =

    "text/css"

    >
  5. <script

    type

    =

    "text/javascript"

    src

    =

    "javascript/timer.js"

    ></

    script

    >
  6. </

    head

    >
  7. <body

    >

  8. <div

    id

    =

    "container"

    >
  9. <p

    id

    =

    "output"

    ></

    p

    >
  10. <div

    id

    =

    "controls"

    >
  11. <button

    class

    =

    "button"

    id

    =

    "startPause"

    onClick

    =

    "startPause()"

    >

    Start</

    button

    >
  12. <br

    /

    >
  13. <br

    /

    >
  14. <button

    class

    =

    "button1"

    onClick

    =

    "reset()"

    >

    Reset</

    button

    >
  15. </

    div

    >
  16. </

    div

    >

  17. </

    body

    >
  18. </

    html

    >

The Result

2_58.png

Hope that this tutorial will help you a lot.

Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.

 

452,292

323,341

323,350

Top