<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>BMI計算アプリ</title>
<style>
body {
text-align: center;
font-family: sans-serif;
background-color: #f0f0f0;
}
h1 {
color: #333333;
}
form {
display: inline-block;
margin-top: 50px;
background-color: #ffffff;
padding: 20px;
border-radius: 10px;
box-shadow: 2px 2px 10px #cccccc;
}
label {
display: inline-block;
margin-bottom: 5px;
}
input[type="text"] {
width: 100px;
margin-right: 10px;
}
input[type="submit"] {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px;
border-radius: 5px;
}
h2 {
margin-top: 50px;
color: #333333;
}
</style>
</head>
<body>
<h1>BMI計算アプリ</h1>
<form>
<label>身長(cm)</label>
<input type="text" id="height" required><br><br>
<label>体重(kg)</label>
<input type="text" id="weight" required><br><br>
<input type="submit" value="BMIを計算する" onclick="calculateBMI()">
</form>
<h2 id="result"></h2>
<script>
function calculateBMI() {
var height = document.getElementById("height").value;
var weight = document.getElementById("weight").value;
var bmi = weight / ((height / 100) * (height / 100));
var result = document.getElementById("result");
if(isNaN(bmi)) {
result.innerText = "身長と体重を正しく入力してください。";
} else {
result.innerText = "あなたのBMIは" + bmi.toFixed(1) + "です。";
}
}
</script>
</body>
</html>
※ジョークは入れていません。