-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
29 lines (26 loc) · 914 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function calculateBMI(height, weight) {
var bmi = (weight * 10000 ) / (height * height);
document.getElementById("result").innerHTML = "Console Log: " + bmi.toFixed(2);
}
function isoverweight(height, weight) {
var bmi = (weight * 10000 ) / (height * height);
if (bmi > 25) {
document.getElementById("knowyou").innerHTML = "You are overweight";
}
else {
document.getElementById("knowyou").innerHTML = "You are not overweight";
}
}
var form = document.querySelector("form");
form.addEventListener("submit", function(event) {
var height = document.getElementById("height").value;
var weight = document.getElementById("weight").value;
if (height == "" || weight == "") {
alert("Please enter your height and weight");
}
else{
event.preventDefault();
calculateBMI(height, weight);
isoverweight(height, weight);
}
});