<!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: 10px 20px;
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=”innings”>投球回(イニング)</label>
<input type=”number” id=”innings” name=”innings” required>
<label for=”outs”> /3(アウト数)</label>
<input type=”number” id=”outs” name=”outs” required>
<label for=”earned-runs”>自責点</label>
<input type=”number” id=”earned-runs” name=”earned-runs” required>
<input type=”submit” value=”計算する”>
</form>
<div class=”result”>
<span id=”result-text”>0.00</span>
</div>
</div>
<script>
const form = document.getElementById(‘calc-form’);
const inningsInput = document.getElementById(‘innings’);
const outsInput = document.getElementById(‘outs’);
const earnedRunsInput = document.getElementById(‘earned-runs’);
const resultText = document.getElementById(‘result-text’);
form.addEventListener(‘submit’, (e) => {
e.preventDefault();
const innings = inningsInput.value;
const outs = outsInput.value;
const earnedRuns = earnedRunsInput.value;
const totalOuts = parseInt(innings) * 3 + parseInt(outs);
const era = (parseFloat(earnedRuns) * 9) / (totalOuts / 3);
resultText.textContent = era.toFixed(2);
});
</script>
</body>
</html>