TZinovieva

Fitness Center JS

Dec 12th, 2022
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function fitnessCenter(input) {
  2.     let visitors = Number(input[0]);
  3.  
  4.     let back = 0;
  5.     let chest = 0;
  6.     let legs = 0;
  7.     let abs = 0;
  8.     let proteinShake = 0;
  9.     let proteinBar = 0;
  10.     let workout = 0;
  11.     let protein = 0;
  12.     for (let i = 1; i <= visitors; i++) {
  13.         let action = input[i];
  14.  
  15.         if (action === "Back") {
  16.             back++;
  17.             workout++;
  18.         } else if (action === "Chest") {
  19.             chest++;
  20.             workout++;
  21.         } else if (action === "Legs") {
  22.             legs++;
  23.             workout++;
  24.         } else if (action === "Abs") {
  25.             abs++;
  26.             workout++;
  27.         } else if (action === "Protein shake") {  
  28.             proteinShake++;
  29.             protein++;
  30.         } else if (action === "Protein bar") {
  31.             proteinBar++;
  32.             protein++;
  33.         }
  34.     }
  35.     console.log(`${back} - back`);
  36.     console.log(`${chest} - chest`);
  37.     console.log(`${legs} - legs`);
  38.     console.log(`${abs} - abs`);
  39.     console.log(`${proteinShake} - protein shake`);
  40.     console.log(`${proteinBar} - protein bar`);
  41.     console.log(`${(workout / visitors * 100).toFixed(2)}% - work out`);
  42.     console.log(`${(protein / visitors * 100).toFixed(2)}% - protein`);
  43. }
Advertisement
Add Comment
Please, Sign In to add comment