AlexandrP

Hair Salon

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