Created
March 3, 2021 12:44
-
-
Save hamidKMB/d43990ba394b37c516f2a4427b576101 to your computer and use it in GitHub Desktop.
BMI Calculator With Calculating How much Weight you must Loose or Gain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Calculating the BMI | |
function BMI(weight , height){ | |
var calcBmi = (weight/(height**2)); | |
return Math.floor(calcBmi*10)/10; | |
} | |
//Checking the Situation of the BMI | |
function situation(bmi) { | |
if(bmi < 18.5){ | |
return "Under Weight"; | |
} | |
if( bmi >= 18.5 && bmi <= 24.9){ | |
return "Normal Weight"; | |
} | |
if( bmi >= 25 && bmi <= 29.9){ | |
return "Over Weight"; | |
} | |
if( bmi >= 30 ){ | |
return "Obesity"; | |
} | |
} | |
//the Weight should be loss or gain | |
function toBeNormal(bmi1 , height1){ | |
if ( bmi1 < 18.5){ | |
var gainWeight = Math.floor ( ( 18.5 - bmi1 ) * 10 ) / 10; | |
gainWeight = Math.floor ( ( gainWeight * ( height1 ** 2 )) * 10 ) / 10; | |
return " | You must gain "+gainWeight+"Kg to be normal"; | |
} | |
if ( bmi1 >= 18.5 && bmi1 <= 24.9){ | |
return " | Keep your body ;-)"; | |
} | |
if ( bmi1 >= 25 ){ | |
var looseWeight = Math.floor ( ( bmi1 - 25 ) * 10 ) / 10; | |
looseWeight = Math.floor ( ( looseWeight * ( height1 ** 2 )) * 10 ) / 10; | |
return " | You must loose "+looseWeight+"Kg to be normal" | |
} | |
} | |
//getting the data from user | |
var weight = prompt("Enter Your Weight in (KG)"); | |
var height = prompt("Enter Your Height in (m2)"); | |
var a = BMI ( weight , height ); | |
//printing the data | |
alert("Your BMI number is: "+ BMI( weight , height ) +" This means you are "+ situation(a) + toBeNormal( a , height )); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment