JSFiddle - React, Tailwind, and code Playground

by huuzoo

HTML

<button onclick="startTimer();">スタート</button>
<button onclick="stopTimer();">ストップ</button>
<button onclick="resetTimer();">リセット</button>
<div>経過時間:<span id="output"></span></div>

JavaScript

var start_time;
var stop_time;
var time;

function startTimer() {
	start_time = Date.now();
	console.log(start_time);
}

function stopTimer() {
	stop_time = Date.now();
	console.log(stop_time);
  time = stop_time - start_time;
  time = time / 1000;
  document.getElementById('output').innerHTML = time + '秒';
}

function resetTimer() {
  document.getElementById('output').innerHTML = '';
}