-Enigmos-

hairdresserSalon.js

Oct 30th, 2021
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function hairdresserSalon(input) {
  2.     let index = 0;
  3.     let moneyGoal = Number(input[index]);
  4.     index++;
  5.     let service = input[index];
  6.     let profit = 0;
  7.  
  8.     while (service !== "closed") {
  9.         if (service === "haircut ladies") {
  10.             profit += 20;
  11.         } else if (service === "haircut kids") {
  12.             profit += 10;
  13.         } else if (service === "haircut mens") {
  14.             profit += 15;
  15.         } else if (service === "touch up") {
  16.             profit += 20;
  17.         } else if (service === "full color") {
  18.             profit += 30;
  19.         }
  20.  
  21.         if (profit >= moneyGoal) {
  22.             break;
  23.         }
  24.  
  25.         service = input[index];
  26.         index++;
  27.     }
  28.     if (profit >= moneyGoal) {
  29.         console.log("You have reached your target for the day!");
  30.         console.log(`Earned money: ${profit}`);
  31.     } else {
  32.         console.log(`Target not reached! You need ${(moneyGoal - profit).toFixed(2)}`);
  33.         console.log(`Earned money: ${profit.toFixed(2)}`);
  34.     }
  35.    
  36. }
  37.  
  38. hairdresserSalon(["300", "haircut ladies", "haircut kids", "color touch up", "closed"]);
  39. hairdresserSalon(["50", "color", "full color", "haircut ladies"]);
Advertisement
Add Comment
Please, Sign In to add comment