-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
115 lines (99 loc) · 4.1 KB
/
index.html
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
108
109
110
111
112
113
114
115
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BMI calculator</title>
<link rel="stylesheet" href="css/style.css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/fonts/remixicon.css" rel="stylesheet">
</head>
<body>
<div class="circles">
<div class="circle9"></div>
<div class="circle10"></div>
<div class="circle11"></div>
<div class="circle12"></div>
<div class="circle13"></div>
<div class="circle14"></div>
<div class="circle15"></div>
</div>
<script>
window.addEventListener("load", function () {
document.querySelector(".circles").style.display = "none";
document.querySelector(".page-content").style.display = "block";
});
</script>
<div class="page-content">
<h2>BMI Calculator</h2>
<p class="text">Height</p>
<input type="text" oninput="this.value=this.value.replace(/[^0-9\.]/g,'').replace(/(\..*)\./g, '$1');" name=""
id="height">
<p class="text">Weight</p>
<input type="text" oninput="this.value=this.value.replace(/[^0-9\.]/g,'').replace(/(\..*)\./g, '$1');" name=""
id="weight">
<p id="result"></p>
<button id="btn" onClick="bmi()">Calculate</button>
<p id="info">Please enter height [cm] and weight [kg] </p>
</div>
<script>
function bmi() {
var h = document.getElementById('height').value;
var w = document.getElementById('weight').value;
if (h && w) {
var bmi = w / (h / 100 * h / 100);
var total = bmi.toFixed(2);
var message;
if (total < 18.5) {
message = "You are under-weight.";
} else if (total >= 18.5 && total <= 24.9) {
message = "You are normal.";
} else {
message = "You are over-weight.";
}
var diff = 0;
if (message !== "You are normal.") {
var targetBmi;
if (message === "You are under-weight.") {
targetBmi = 18.5;
} else if (message === "You are over-weight.") {
targetBmi = 24.9;
}
var targetW = targetBmi * (h / 100 * h / 100);
diff = targetW - w;
}
var resultText = "Your BMI is " + total + "<br>" + message + "<br>";
if (diff > 0) {
resultText += "You need to gain minimum " + diff.toFixed(2) + " kg to reach a normal BMI.";
} else if (diff < 0) {
resultText += "You need to lose minimum " + (-diff).toFixed(2) + " kg to reach a normal BMI.";
} else {
resultText += "You are already at a normal weight for your height.";
}
document.getElementById('result').innerHTML = resultText;
} else {
document.getElementById('result').innerHTML = "Enter your height and weight first.";
}
}
</script>
<footer class="footer">
<div class="wrapper">
<div class="icon facebook">
<span><i class="ri-facebook-fill"></i></span>
</div>
<div class="icon instagram">
<span><i class="ri-instagram-line"></i></span>
</div>
<div class="icon twitter">
<span><i class="ri-twitter-fill"></i></span>
</div>
<div class="icon whatsapp">
<span><i class="ri-whatsapp-line"></i></span>
</div>
<div class="icon youtube">
<span><i class="ri-youtube-fill"></i></span>
</div>
</div>
</footer>
</body>
</html>