You are on page 1of 2

CODE

<html>
<head>
<title>BMI Calculator</title>
</head>
<body>
<h1>BMI Calculator</h1>
<label>Enter your weight (kg):</label>
<input type=”number” id=”weight” step=”0.01”><br>
<label>Enter your height (m):</label>
<input type=”number” id=”height” step=”0.01”><br>
<button onclick=”calculateBMI()”>Calculate BMI</button>
<p>Your BMI is: <span id=”result”></span></p>

<script>
Function calculateBMI() {
Var weight = parseFloat(document.getElementById(“weight”).value);
Var height = parseFloat(document.getElementById(“height”).value);

If (isNaN(weight) || isNaN(height)) {
Alert(“Please enter valid weight and height.”);
Return;
}
Var bmi = weight / (height * height);
Document.getElementById(“result”).textContent = bmi.toFixed(2);
}
</script>
</body>
</html>

You might also like