-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBmi.html
More file actions
107 lines (98 loc) · 2.86 KB
/
Bmi.html
File metadata and controls
107 lines (98 loc) · 2.86 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BMI calculator</title>
<style>
body{
text-align: center;
font-family: 'Times New Roman', Times, serif;
}
.container{
width: 400px;
border: 3px solid black;
border-radius: 8px;
margin: 5px auto;
margin-top:20px;
}
h1{
letter-spacing: 2px;
}
input{
width:55%;
padding: 9px;
font-size: 20px;
border: 1px solid grey;
border-radius: 5px;
margin-left: 3px;
margin-top: 3px;
}
p{
font-size: 23px;
margin: 3px;
}
button{
padding: 12px;
font-size: 20px;
background-color: black;
color: white;
border: 1px solid black;
border-radius: 7px;
margin: 5px;
}
.description{
text-align: center;
margin: 8px;
font-size: 20px;
}
.res{
font-size: 23px;
font-weight: 500;
}
</style>
</head>
<body>
<div class="container">
<h1>BMI APP</h1>
<form action="#">
<p><label for="text">Height in cm:</label><input type="text" id="text" placeholder="Enter Height"></p>
<p><label for="texts">Weight in cm:</label><input type="text" id="texts" placeholder="Enter Weight"></p>
<button>Calculate</button>
<div class="res"></div>
<div class="description">
<h2>BMI Overview:</h2>
<p>Over weight: Less than 18.6</p>
<p>Normal weight: 18.6 - 24.9</p>
<p>Under Weight: More than 24.9</p>
</div>
</form>
</div>
<script>
let btn = document.querySelector("button");
let res = document.querySelector(".res");
let form = document.querySelector("form");
form.addEventListener("submit",(e)=>{
e.preventDefault();
let height = parseInt(document.querySelector("#text").value);
let weight = parseInt(document.querySelector("#texts").value);
let res = document.querySelector(".res");
res.classList.add("res");
if(height === "" || height < 0 || isNaN(height)){
res.innerText = `Please give Valid height`;
res.style.color = "red";
}
else if(weight === "" || weight < 0 || isNaN(weight)){//weight != NaN
res.innerText = `please give Valid weight`;
res.style.color = "red";
}
else{
let bmi = (weight / ((height*height)/10000)).toFixed(2);
console.log(bmi);
res.innerText = `BMI is: ${bmi}`;
res.style.color = "green";
}
})
</script>
</body>
</html>