Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@upgundecha
Created January 21, 2018 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save upgundecha/7b4cc0dc5cfbee09e059cbafca45cfe3 to your computer and use it in GitHub Desktop.
Save upgundecha/7b4cc0dc5cfbee09e059cbafca45cfe3 to your computer and use it in GitHub Desktop.
Simple BMI Calculator Lambda function
'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