Skip to content
/ timer Public

A simple timer to measuring time intervals implemented with JavasScript

License

Notifications You must be signed in to change notification settings

AleNoia/timer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🕰️ Timer

A simple timer to measuring time interval implemented swith JavaScript

If you want to contact, mail me or send a message on Twitter

📧 igornoiasilva@gmail.com / ☕ @IgorNoiaSilva


📌 Table of Contents


💡 Features

  • 🕒 Measure your time.
  • 🛑 You can stop the timer.
  • 🔁 You can reset the timer.

🎯 Purpose

My purpose with this project is to

  • learn how to use setInterval and clearInterval
  • learn how to work with dates
  • how to use addEventListener in a better way
  • learn more about Javascript.

🛠 Installation

Run this command to clone the repository:


git clone https://github.com/AleNoia/timer.git


📝 Utilization

You can start the timer by clicking the Start button.

let seconds = 0 // variable of the time to manipulate
let timer; // variable of the setInterval to use clearInterval

// Return a string formatted 
function getTime(sec) {
    const date = new Date(sec * 1000);
    return date.toLocaleTimeString('pt-BR', {
        hour12: false,
        timeZone: 'GMT'
    });
}

// Insert a string on the HTML and start the timer
function startTimer() {
    clearInterval(timer)
    timer = setInterval(function () {
        seconds++
        clock.innerHTML = getTime(seconds);
    }, 1000)
}

// Event to start the timer
if (el.classList.contains('start')) {
    startTimer()
}

To stop the timer, click on the button Stop

// Event to stop the timer
if (el.classList.contains('stop')) {
    clearInterval(timer)
}

To reset the timer, click on the button Reset

// Reset the timer to 00:00:00
function resetTime() {
    seconds = 0;
    clock.innerHTML = getTime(seconds);
    clearInterval(timer)
}

// Event to reset the timer
if (el.classList.contains('reset')) {
    resetTime()
}

🤝 Contributing

Feel free to contribute 🙂


🧾 License

Released in 2021. This project is under the MIT license.

Made by Igor Noia 👋

About

A simple timer to measuring time intervals implemented with JavasScript

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published