borisova936935

Untitled

Nov 14th, 2021
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function hairSalon(input) {
  2.  
  3.     let index = 0;
  4.     let target = input[index];
  5.     index++;
  6.  
  7.     let command = input[index];
  8.     index++;
  9.  
  10.     let sum = 0;
  11.  
  12.     let isCollected = false;
  13.  
  14.     while (command !== "closed") {
  15.         let action = command;
  16.         let type = input[index];
  17.         index++;
  18.  
  19.         if (action === "haircut") {
  20.             if (type === "mens") {
  21.                 sum += 15;
  22.             } else if (type === "ladies") {
  23.                 sum += 20;
  24.             } else if (type === "kids") {
  25.                 sum += 10;
  26.             }
  27.  
  28.         } else if (action === "color") {
  29.             if (type === "touch up") {
  30.                 sum += 20;
  31.             } else if (type === "full color") {
  32.                 sum += 30;
  33.             }
  34.         }
  35.  
  36.  
  37.         if (sum >= target) {
  38.             isCollected = true;
  39.             console.log("You have reached your target for the day!");
  40.             break;
  41.         }
  42.         command = input[index];
  43.         index++;
  44.  
  45.     }
  46.  
  47.     let diff = Math.abs(target - sum)
  48.  
  49.     if (!isCollected) {
  50.         console.log(`Target not reached! You need ${diff}lv. more.`);
  51.     }
  52.     console.log(console.log(`Earned money: ${sum}lv.`));
  53.  
  54. }
  55. hairSalon(["300",
  56.     "haircut",
  57.     "ladies",
  58.     "haircut",
  59.     "kids",
  60.     "color",
  61.     "touch up",
  62.     "closed"])
Advertisement
Add Comment
Please, Sign In to add comment