Hello. Below is my current code. It is suppose to output the height, weight, bod
ID: 3770554 • Letter: H
Question
Hello. Below is my current code. It is suppose to output the height, weight, body mass index and the result. It displays all of that besides the body mass index. The body mass index also has to be rounded to two decimal places. Any suggestions would be greatly appreciated.
<!DOCTYPE html>
< html lang="en">
<head> <!-- open of head -->
<meta charset="utf-8">
<title> Mikayla's Kung Fu Panda Po Body Mass Index </title>
<link rel="shortcut icon" href="me.jpg">
<link rel="stylesheet" href="style.css"> <!-- connects to style sheet -->
< /head>
< body> <!-- beginning of the body section -->
<header>
<h1> Mikayla's Kung Fu Panda<br>Po Body Mass Index </h1>
</header>
<div id= "main">
<div id= "p">
<p>
This page will prompt Mikayla for Kung Fu Panda Po's height and weight.
The program will convert the given input into Po's body mass index, and
will inform Mikayla if Po is overweight or underweight.
<br>
</p>
</div>
</div> <!-- end of div "main" -->
<script type="text/javascript">
function getBMI()
{
var height = document.getElementById("poHeight").value;
var weight = document.getElementById("poWeight").value;
var bmi = ((weight * 703) / (height * height));
document.getElementById("bmi").innerHTML = " " + bmi + " ";
if (bmi < 18)
{
document.getElementById("newText").innerHTML = "Po is Underweight";
}
else if (bmi >= 18 && bmi< = 24.9)
{
document.getElementById("newText").innerHTML = "Po has normal weight";
}
else if (bmi >= 25 && bmi< = 29.9)
{
document.getElementById("newText").innerHTML = "Po is overweight";
}
else if (bmi > 30)
{
document.getElementById("newText").innerHTML = "Po is obese";
}
}
function getWeightAndHeight()
{
var height = prompt("Enter Po's height");
document.getElementById("poHeight").innerHTML = height;
document.getElementById("poHeight").value = height;
var weight = prompt("Enter Po's weight");
document.getElementById("poWeight").innerHTML = weight;
document.getElementById("poWeight").value = weight;
getBMI();
}
</script>
<p>
BMI = weight x 703 / height²
<br><br>
Weight in pounds. Height in inches.
<br><br>
If Po's BMI is less than 18. Po is underweight
<br><br>
If Po's BMI is between 18 and 24.9. Po has normal weight
<br><br>
If Po's BMI is between 25 and 29.9. Po is overweight
<br><br>
If Po's BMI is greater than 30, Po is obese
<br><br>
</p>
<h2>
Click on the button below to enter Po's weight and height.
</h2>
<div id="container1">
<p><input type="button" value="Enter Mikayla's Po weight and height"
onclick="getWeightAndHeight();"></p>
<p>Po's BMI: </p>
<p>Po's height is: <span id="poHeight"> </span> </p>
<p>Po's weight is: <span id="poWeight"> </span> </p>
<p>Po's current Body Mass Index:< span id="bmi"> </span></p>
<p id="newText"><br>
</div>
</body>
< /html>
Explanation / Answer
Check this
Added new line
Math.round(num * 100) / 100
< html lang="en">
<head> <!-- open of head -->
<meta charset="utf-8">
<title> Mikayla's Kung Fu Panda Po Body Mass Index </title>
<link rel="shortcut icon" href="me.jpg">
<link rel="stylesheet" href="style.css"> <!-- connects to style sheet -->
< /head>
< body> <!-- beginning of the body section -->
<header>
<h1> Mikayla's Kung Fu Panda<br>Po Body Mass Index </h1>
</header>
<div id= "main">
<div id= "p">
<p>
This page will prompt Mikayla for Kung Fu Panda Po's height and weight.
The program will convert the given input into Po's body mass index, and
will inform Mikayla if Po is overweight or underweight.
<br>
</p>
</div>
</div> <!-- end of div "main" -->
<script type="text/javascript">
function getBMI()
{
var height = document.getElementById("poHeight").value;
var weight = document.getElementById("poWeight").value;
var bmi = ((weight * 703) / (height * height));
//Added new line for TWO decimal places..
bmi=Math.round(bmi * 100) / 100
document.getElementById("bmi").innerHTML = " " + bmi + " ";
if (bmi < 18)
{
document.getElementById("newText").innerHTML = "Po is Underweight";
}
else if (bmi >= 18 && bmi< = 24.9)
{
document.getElementById("newText").innerHTML = "Po has normal weight";
}
else if (bmi >= 25 && bmi< = 29.9)
{
document.getElementById("newText").innerHTML = "Po is overweight";
}
else if (bmi > 30)
{
document.getElementById("newText").innerHTML = "Po is obese";
}
}
function getWeightAndHeight()
{
var height = prompt("Enter Po's height");
document.getElementById("poHeight").innerHTML = height;
document.getElementById("poHeight").value = height;
var weight = prompt("Enter Po's weight");
document.getElementById("poWeight").innerHTML = weight;
document.getElementById("poWeight").value = weight;
getBMI();
}
</script>
<p>
BMI = weight x 703 / height²
<br><br>
Weight in pounds. Height in inches.
<br><br>
If Po's BMI is less than 18. Po is underweight
<br><br>
If Po's BMI is between 18 and 24.9. Po has normal weight
<br><br>
If Po's BMI is between 25 and 29.9. Po is overweight
<br><br>
If Po's BMI is greater than 30, Po is obese
<br><br>
</p>
<h2>
Click on the button below to enter Po's weight and height.
</h2>
<div id="container1">
<p><input type="button" value="Enter Mikayla's Po weight and height"
></p>
<p>Po's BMI: </p>
<p>Po's height is: <span id="poHeight"> </span> </p>
<p>Po's weight is: <span id="poWeight"> </span> </p>
<p>Po's current Body Mass Index:< span id="bmi"> </span></p>
<p id="newText"><br>
</div>
</body>
< /html>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.