Advertisement
Spocoman

Calorie Calculator

Sep 23rd, 2023
798
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function calorieCalculator(input) {
  2.    let gender = input[0];
  3. let weight = Number(input[1]);
  4.             let height = Number(input[2]);
  5.             let age = Number(input[3]);
  6.             let physicalActivity = input[4];
  7.  
  8.             let basalMetabolicRate;
  9.             let coefficientActivity;
  10.  
  11.             if (gender == 'm') {
  12.                 basalMetabolicRate = 66 + weight * 13.7 + height * 500 - 6.8 * age;
  13.             } else {
  14.                 basalMetabolicRate = 655 + weight * 9.6 + height * 180 - 4.7 * age;
  15.             }
  16.  
  17.             if (physicalActivity == "sedentary") {
  18.                 coefficientActivity = 1.2;
  19.             } else if (physicalActivity == "lightly active") {
  20.                 coefficientActivity = 1.375;
  21.             } else if (physicalActivity == "moderately active") {
  22.                 coefficientActivity = 1.55;
  23.             } else {
  24.                 coefficientActivity = 1.725;
  25.             }
  26.  
  27.             let calories = basalMetabolicRate * coefficientActivity;
  28.  
  29.             console.log(`To maintain your current weight you will need ${Math.ceil(calories)} calories per day.`);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement