-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBMICalculator.js
46 lines (25 loc) · 1.06 KB
/
BMICalculator.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const form = document.querySelector('form');
form.addEventListener('submit', function (e) {
console.log(e);
e.preventDefault();
const height = parseInt(document.querySelector('#height').value);
console.log(height);
const weight = parseInt(document.querySelector('#weight').value);
console.log(weight);
const results = document.querySelector('#results');
const element = document.createElement('button');
element.innerHTML = `<div></div>`;
if (height < 0 || height === '' || height === isNaN()) {
document.querySelector('button').style.display = "none";
results.innerHTML = "Enter a valid height";
}
else if (weight < 0 || weight === '' || weight === isNaN()) {
document.querySelector('button').style.display = "none";
results.innerHTML = "Enter a valid weight";
}
else {
document.querySelector('button').style.display = "none";
const bmi = (weight / ((height * height) / 10000)).toFixed(2);
results.innerHTML = `<span>Bmi is ${bmi}</span>`;
}
})