Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add funtionalites
  • Loading branch information
tajulafreen committed Jul 22, 2024
commit ccb44260960cb6538e621a2e9f7e7ae06843a777
20 changes: 20 additions & 0 deletions Source-Code/BMICalculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
document.getElementById('btn').addEventListener('click', () => {
const height = parseFloat(document.getElementById('height').value);
const weight = parseFloat(document.getElementById('weight').value);

if (
Number.isNaN(height)
|| Number.isNaN(weight)
|| height <= 0
|| weight <= 0
) {
document.getElementById('result').innerHTML = 'Please enter valid positive numbers for height and weight.';
return;
}

const heightInMeters = height / 100;
const bmi = weight / (heightInMeters * heightInMeters);
const bmio = bmi.toFixed(2);

document.getElementById('result').innerHTML = `Your BMI is ${bmio}`;
});