Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions timers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
//selectors for stopwatch buttons
let $reset = $("#reset");
let $start = $("#start");
let $pause = $("#pause");
let $timer = $("#timer");

//declare variables for seconds and timerID
let seconds = 0;
let timerID = 0;
//create update timer function
let updateTimer = function(){
timerID = setInterval(updateSeconds, 1000);
};
//increments the seconds
let updateSeconds = function(){
seconds++;
console.log(seconds);
$timer.html(seconds);
};
let pauseTime = function(){
clearInterval(timerID);
};
let resetTime = function(){
clearInterval(timerID);
seconds = 0;
$timer.html("Stop Watch");
};



$reset.on("click", resetTime);
$start.on("click", updateTimer);
$pause.on("click", pauseTime);
//Bug with clicking start multiple times starts a new start ID