Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ button {
box-shadow: 2px 2px black;
}

.cyan {
background-color: cyan;
color: black;
}

button:hover{
background: #356094;
}

45 changes: 45 additions & 0 deletions timers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,49 @@
$(document).ready(function(){

var seconds = 0;
var minutes = 0;
var timerID;
var pauseRemoveCyan = function() {$('#pause').removeClass('cyan');};
var startRemoveCyan = function() {$('#start').removeClass('cyan');};

function updateTime() {
seconds++;

// increment minutes
if(seconds > 59) {
minutes++;
seconds = 0;
}
//concatenate zero to single digit
if (seconds < 10) {
seconds = "0" + seconds;
}

//displays minutes & seconds
$('#timer').text(minutes + " : " + seconds);
}

//starts timer
$('#start').on('click', function(){
timerID = setInterval(updateTime, 1000);
$(this).addClass('cyan');
pauseRemoveCyan();
})

//pauses timer
$('#pause').on('click', function(){
clearInterval(timerID);
$(this).addClass('cyan');
startRemoveCyan();
})

//resets timer
$('#reset').on('click', function(){
clearInterval(timerID);
seconds = 0;
pauseRemoveCyan();
startRemoveCyan();
$('#timer').text("Stop Watch");
})

})