Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let dailyTarget = Number(input.shift());
- let earnedMoney = 0;
- let command = input.shift();
- while (command !== 'closed') {
- let type = input.shift();
- if (command === 'haircut') {
- switch (type) {
- case 'mens':
- earnedMoney += 15;
- break;
- case 'ladies':
- earnedMoney += 20;
- break;
- case 'kids':
- earnedMoney += 10;
- break;
- }
- } else if (command === 'color') {
- switch (type) {
- case 'touch up':
- earnedMoney += 20;
- break;
- case 'full color':
- earnedMoney += 30;
- break;
- }
- }
- if (earnedMoney >= dailyTarget) {
- console.log('You have reached your target for the day!');
- console.log(`Earned money: ${earnedMoney}lv.`);
- return;
- }
- command = input.shift();
- }
- if (earnedMoney < dailyTarget) {
- console.log(`Target not reached! You need ${dailyTarget - earnedMoney}lv. more.`);
- console.log(`Earned money: ${earnedMoney}lv.`);
- return;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement