0% found this document useful (0 votes)
31 views2 pages

Code Bmi

This document contains code for a BMI calculator web page. It includes fields for a user to enter their weight in kilograms and height in meters, and a button to trigger a JavaScript function to calculate BMI based on those values. The calculated BMI is then displayed on the page below the input fields. The JavaScript function checks that valid numbers are entered and displays an alert if not before performing the BMI calculation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views2 pages

Code Bmi

This document contains code for a BMI calculator web page. It includes fields for a user to enter their weight in kilograms and height in meters, and a button to trigger a JavaScript function to calculate BMI based on those values. The calculated BMI is then displayed on the page below the input fields. The JavaScript function checks that valid numbers are entered and displays an alert if not before performing the BMI calculation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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