Created
January 21, 2018 11:58
-
-
Save upgundecha/7b4cc0dc5cfbee09e059cbafca45cfe3 to your computer and use it in GitHub Desktop.
Simple BMI Calculator Lambda function
This file contains hidden or 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
'use strict'; | |
exports.handler = function(event, context, callback){ | |
var height = event.height; | |
var weight = event.weight; | |
var bmi = weight/(height * height) * 10000; | |
bmi = Math.round ( bmi * 100 ) / 100; | |
if (bmi < 18.5) { | |
var category = "Underweight"; | |
} | |
else if((bmi >= 18.5) && (bmi <= 24.9)) { | |
var category = "Normal"; | |
} else if((bmi >= 25) && (bmi <= 29.9)) { | |
var category = "Overweight"; | |
} | |
else if(bmi >= 30) { | |
var category = "Obese"; | |
} | |
var result = { | |
bmi: bmi, | |
category: category | |
}; | |
callback(null, result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment