AleNoia / timer

A simple timer to measuring time intervals implemented with JavasScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸ•°οΈ 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

License:MIT License


Languages

Language:JavaScript 71.1%Language:HTML 28.9%