Coder Social home page Coder Social logo

esleiter / chronometer Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 11 KB

Start, pause, and track time effortlessly. Measure milliseconds, seconds, and minutes precisely. Perfect for accurate timekeeping!

Home Page: https://chronometer.esleiter.com

HTML 60.70% JavaScript 31.60% CSS 7.70%
chronometer javascript vanilla-js web-development

chronometer's Introduction

Chronometer โŒ›

Start, pause, and track time effortlessly. Measure milliseconds, seconds, and minutes precisely. Perfect for accurate timekeeping!

Table of Contents

  1. General Info
  2. Screenshot

General Info

The code you provided is a simple JavaScript implementation of a chronometer (or stopwatch) functionality. It uses HTML elements to display the elapsed time in milliseconds, seconds, and minutes. Here's a breakdown of the code:

The variables ms, s, and m are initialized to 0. These variables will keep track of the milliseconds, seconds, and minutes, respectively.

The variable chronometer is declared to store the interval ID returned by setInterval(). This ID is used to later clear the interval when necessary.

The Start() function is called when you want to start the chronometer. It sets the chronometer variable to the result of setInterval(Increase, 10), which calls the Increase() function every 10 milliseconds. This function updates the time display and increments the milliseconds.

The Pause() function is called to pause the chronometer. It clears the interval using clearInterval(chronometer). The "Play" button's disabled state is updated to allow resuming.

The Stop() function is called to stop the chronometer and reset the time. It clears the interval, resets the ms, s, and m variables to 0, and enables the "Play" button.

The Increase() function is the main logic for updating the time display. It increments the ms variable by 1 and calculates the corresponding milliseconds to display using mseg = Math.trunc(((ms / 100) - s) * 100). It then updates the HTML elements with the new values for milliseconds, seconds, and minutes.

If the seconds (s) reach 60, it resets ms to 0 and increments the minutes (m) by 1. Finally, it updates the corresponding HTML elements for seconds and minutes.

Screenshot

Image text

chronometer's People

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.