From 2458fedeb51303572805d85f15b2508783dee7af Mon Sep 17 00:00:00 2001 From: Raj Shekhar Date: Sun, 3 Nov 2024 16:34:18 +0530 Subject: [PATCH] BMI Calculator --- projects/02_BMI_Calculator/index.html | 35 ++++++++++++++++++++ projects/02_BMI_Calculator/script.js | 24 ++++++++++++++ projects/02_BMI_Calculator/style.css | 47 +++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 projects/02_BMI_Calculator/index.html create mode 100644 projects/02_BMI_Calculator/script.js create mode 100644 projects/02_BMI_Calculator/style.css diff --git a/projects/02_BMI_Calculator/index.html b/projects/02_BMI_Calculator/index.html new file mode 100644 index 0000000..b04e071 --- /dev/null +++ b/projects/02_BMI_Calculator/index.html @@ -0,0 +1,35 @@ + + + + + + + + + BMI Calculator + + + +
+

BMI Calculator

+
+

+

+ +
+
+

BMI Weight Guide

+

Under Weight = Less than 18.6

+

Normal Range = 18.6 and 24.9

+

Overweight = Greater than 24.9

+
+
+
+ + + diff --git a/projects/02_BMI_Calculator/script.js b/projects/02_BMI_Calculator/script.js new file mode 100644 index 0000000..046b9d1 --- /dev/null +++ b/projects/02_BMI_Calculator/script.js @@ -0,0 +1,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)) { + results.innerHTML = `please enter a valid height ${height}`; + } else if (weight === '' || weight < 0 || isNaN(weight)) { + results.innerHTML = `please enter a valid weight ${weight}`; + } else { + const bmi = (weight / ((height * height) / 10000)).toFixed(2); + if (bmi < 18.6) { + results.innerHTML = `BMI = ${bmi}

Underweight

`; + } else if (bmi == 18.6 || bmi < 24.9) { + results.innerHTML = `BMI = ${bmi}

Normal RangeBMI = ${bmi}

Overweight