설명
document.getElementId, .innerHTML 등 활용해보기

HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>stopwatch</title>
</head>
<body>
<div class="wrapper">
<h1>Stopwatch</h1>
<p><span id="seconds">0</span>:<span id="tens">0</span></p>
<button id="button-start">Start</button>
<button id="button-stop">Stop</button>
<button id="button-reset">Reset</button>
</div>
<script src="script.js"></script>
</body>
</html>
JS
const appendTens = document.getElementById('tens');
const appendSeconds = document.getElementById('seconds');
const buttonStart = document.getElementById('button-start');
const buttonStop = document.getElementById('button-stop');
const buttonReset = document.getElementById('button-reset');
let seconds = 0;
let tens = 0;
let interval;
buttonStart.onclick = function() {
interval = setInterval(startTimer, 10)
}
buttonStop.onclick = function() {
clearInterval(interval);
}
buttonReset.onclick = function() {
clearInterval(interval);
tens = 0;
seconds = 0;
appendTens.innerHTML = 0;
appendSeconds.innerHTML = 0;
}
function startTimer () {
tens++;
if (tens > 99) {
seconds++;
appendSeconds.innerHTML = seconds;
tens = 0;
appendTens.innerHTML = tens;
} else {
appendTens.innerHTML = tens;
}
}