Advertisement
braveheart1989

04. Perosnal BM

Oct 23rd, 2016
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function result(input) {
  2.     let name = arguments[0];
  3.     let age = arguments[1];
  4.     let weight = Number(arguments[2]);
  5.     let height = Number(arguments[3]) / 100;
  6.     let BMI = weight / (height * height);
  7.     let status = checkStatus(BMI);
  8.  
  9.     return (function () {
  10.         if (status === "obese") {
  11.             return {
  12.                 name: name,
  13.                 personalInfo: {
  14.                     age: age,
  15.                     weight: weight,
  16.                     height: height * 100
  17.                 },
  18.                 BMI: Math.round(BMI),
  19.                 status: status,
  20.                 recommendation:'admission required'
  21.             };
  22.         }
  23.         else {
  24.             return {
  25.                 name: name,
  26.                 personalInfo: {
  27.                     age: age,
  28.                     weight: weight,
  29.                     height: height * 100
  30.                 },
  31.                 BMI: Math.round(BMI),
  32.                 status: status
  33.             };
  34.         }
  35.     })();
  36.  
  37.  
  38.     function checkStatus(bmi) {
  39.         let status = '';
  40.         if (bmi < 18.5) {
  41.             status = "underweight";
  42.         }
  43.         else if (bmi >= 18.5 && bmi < 25) {
  44.             status = "normal";
  45.         }
  46.         else if (bmi >= 25 && bmi < 30) {
  47.             status = "overweight"
  48.         }
  49.         else {
  50.             status = "obese";
  51.         }
  52.         return status;
  53.     }
  54. }
  55. console.log(result("Honey Boo Boo", 9, 57, 137));
  56. console.log(result("Honey Boo Boo", 29, 75, 182));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement