-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
24 lines (18 loc) · 784 Bytes
/
Copy pathscript.js
File metadata and controls
24 lines (18 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const form = document.querySelector('form');
form.addEventListener('submit', function(e){
e.preventDefault();
const height = parseInt(document.querySelector('#height').value);
const weight = parseInt(document.querySelector('#weight').value);
const results = document.querySelector('#results');
if((height === '') || (height < 0) || (isNaN(height))){
//NaN !== NaN
results.innerHTML = "Please provide a valid height";
} else if (weight === '' || weight < 0 || isNaN(weight)){
results.innerHTML = "Please provide a valid weight";
} else {
//calculate BMI
const bmi = (weight / ((height*height)/10000)).toFixed(2);
//display the results
results.innerHTML = `<span>${bmi}</span>`
}
});