You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.1 KiB
39 lines
1.1 KiB
let startTime = 0;
|
|
let windowInterval;
|
|
|
|
const padDigits = (value) => {
|
|
if(value < 10){
|
|
return '0'+value;
|
|
} else {
|
|
return value;
|
|
}
|
|
}
|
|
|
|
const formatTime = (total) => {
|
|
const hours = Math.floor(total/60/60);
|
|
const minutes = Math.floor( (total - (hours*60*60)) / 60 );
|
|
const seconds = total - minutes*60 - hours * 60 * 60;
|
|
return `${padDigits(hours)}:${padDigits(minutes)}:${padDigits(seconds)}`;
|
|
}
|
|
|
|
const displayTime = () => {
|
|
startTime++;
|
|
document.querySelector('h1').innerHTML = formatTime(startTime);
|
|
}
|
|
|
|
document.querySelector('.btn-primary').addEventListener('click', (event) => {
|
|
document.querySelector('.btn-primary').disabled=true;
|
|
document.querySelector('.btn-secondary').disabled=false;
|
|
windowInterval = window.setInterval(displayTime,1000)
|
|
})
|
|
|
|
document.querySelector('.btn-secondary').addEventListener('click', (event) => {
|
|
document.querySelector('.btn-primary').disabled=false;
|
|
document.querySelector('.btn-secondary').disabled=true;
|
|
window.clearInterval(windowInterval)
|
|
})
|
|
|
|
// window.onbeforeunload = function(){
|
|
// return 'Good bye';
|
|
// }
|