Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
week 10 stopwatch
  • Loading branch information
yuk23003 committed Mar 31, 2024
1 parent 5edcea6 commit 820eae3
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions week-10/index.html
@@ -0,0 +1,58 @@
// Making stopwatch

<section>
<p1>0m</p1>
<p2>0s</p2>

<button id="start">Start</button>
<button id="reset">Reset</button>

</section>

<script>

let start = document.querySelector("#start")
let stop = document.querySelector("#stop")
let restart = document.querySelector("#restart")
let p1 = document.querySelector("p1")
let p2 = document.querySelector("p2")

let seconds = 0;
let minutes = 0;
let timer;

function startTimer(){
timer = setInterval(updateDisplay, 1000)
updateDisplay()
};

function updateDisplay(){
if (seconds == 59){
minutes = minutes + 1;
seconds = -1;
}

seconds++;
p1.innerHTML = `${minutes}m`
p2.innerHTML = `${seconds}s`
console.log("interval running", seconds)
}

function stopTimer(){
clearInterval(timer)
}

function resetTimer(){
stopTimer()
console.log("reset")
seconds = -1;
minutes = 0;
updateDisplay()
}

start.addEventListener('click', startTimer)
reset.addEventListener('click', resetTimer)


</script>

0 comments on commit 820eae3

Please sign in to comment.