kstoyanov

03. Personal BMI

Oct 9th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function personData(...input) {
  2.   const [name, age, weight, height] = input;
  3.   const heigthM = height / 100;
  4.   const BMI = Math.round(weight / heigthM ** 2, 1);
  5.  
  6.   const personalInfo = {
  7.     age,
  8.     weight,
  9.     height,
  10.   };
  11.  
  12.   const status = (function () {
  13.     if (BMI < 18.5) {
  14.       return 'underweight';
  15.     }
  16.     if (BMI < 25) {
  17.       return 'normal';
  18.     }
  19.     if (BMI < 30) {
  20.       return 'overweight';
  21.     }
  22.     return 'obese';
  23.   }());
  24.  
  25.   const person = {
  26.     name,
  27.     personalInfo,
  28.     BMI,
  29.     status,
  30.   };
  31.  
  32.   if (status === 'obese') {
  33.     person.recommendation = 'admission required';
  34.   }
  35.  
  36.   return person;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment