<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<meta http-equiv=”X-UA-Compatible” content=”ie=edge”>
<title>速度計算機</title>
<style>
* {
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
font-size: 16px;
line-height: 1.6;
margin: 0;
padding: 0;
}
.container {
max-width: 500px;
margin: 0 auto;
padding: 20px;
}
h1 {
text-align: center;
font-size: 24px;
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 10px;
}
input[type=”number”] {
width: 100%;
padding: 10px;
font-size: 16px;
margin-bottom: 20px;
border: 1px solid #ccc;
border-radius: 4px;
}
input[type=”submit”] {
background-color: #4CAF50;
color: #fff;
padding: 15px 30px;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type=”submit”]:hover {
background-color: #3e8e41;
}
.result {
text-align: center;
font-size: 24px;
margin-top: 20px;
}
</style>
</head>
<body>
<div class=”container”>
<h1>速度計算機</h1>
<form id=”calc-form”>
<label for=”distance”>距離(km)</label>
<input type=”number” id=”distance” name=”distance” required>
<label for=”hour”>時間(時)</label>
<input type=”number” id=”hour” name=”hour” required>
<label for=”minute”>時間(分)</label>
<input type=”number” id=”minute” name=”minute” required>
<input type=”submit” value=”計算する”>
</form>
<div class=”result”>
<span id=”result-text”>0</span> km/h
</div>
</div>
<script>
const form = document.getElementById(‘calc-form’);
const distanceInput = document.getElementById(‘distance’);
const hourInput = document.getElementById(‘hour’);
const minuteInput = document.getElementById(‘minute’);
const resultText = document.getElementById(‘result-text’);
form.addEventListener(‘submit’, (e) => {
e.preventDefault();
const distance = distanceInput.value;
const hour = hourInput.value;
const minute = minuteInput.value;
const time = parseInt(hour) + parseInt(minute) / 60; // 分を時に変換する
const speed = distance / time;
resultText.textContent = speed.toFixed(2);
});
</script>
</body>
</html>