Advertisement
mivebe

Ex: 32 - Barber shop

Nov 1st, 2020 (edited)
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.32 KB | Software | 0 0
  1. function solve(input) {
  2.     let dailyTarget = Number(input.shift());
  3.     let earnedMoney = 0;
  4.     let command = input.shift();
  5.  
  6.     while (command !== 'closed') {
  7.         let type = input.shift();
  8.  
  9.         if (command === 'haircut') {
  10.             switch (type) {
  11.                 case 'mens':
  12.                     earnedMoney += 15;
  13.                     break;
  14.                 case 'ladies':
  15.                     earnedMoney += 20;
  16.                     break;
  17.                 case 'kids':
  18.                     earnedMoney += 10;
  19.                     break;
  20.             }
  21.         } else if (command === 'color') {
  22.             switch (type) {
  23.                 case 'touch up':
  24.                     earnedMoney += 20;
  25.                     break;
  26.                 case 'full color':
  27.                     earnedMoney += 30;
  28.                     break;
  29.             }
  30.         }
  31.  
  32.         if (earnedMoney >= dailyTarget) {
  33.             console.log('You have reached your target for the day!');
  34.             console.log(`Earned money: ${earnedMoney}lv.`);
  35.             return;
  36.         }
  37.         command = input.shift();
  38.     }
  39.  
  40.  
  41.     if (earnedMoney < dailyTarget) {
  42.         console.log(`Target not reached! You need ${dailyTarget - earnedMoney}lv. more.`);
  43.         console.log(`Earned money: ${earnedMoney}lv.`);
  44.         return;
  45.     }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement