Skip to content

Instantly share code, notes, and snippets.

@jcouyang
Last active September 10, 2017 03:20
Show Gist options
  • Save jcouyang/edc3d175769e893b39e6c5be12a8526f to your computer and use it in GitHub Desktop.
Save jcouyang/edc3d175769e893b39e6c5be12a8526f to your computer and use it in GitHub Desktop.
BMI Calculator
height = params['height'].to_f
weight = params['weight'].to_f
bmi = weight * 10000.0 / (height * height)
health = if(bmi < 18.5)
'underweight'
elsif (bmi < 24.9)
'normal'
elsif (bmi < 30)
'Overweight'
elsif (bmi >= 30)
'Obese'
end
{
:health => health,
:bmi => bmi.round(2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment