Advertisement
Neri0817

Hair Salon

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