Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function hairSalon(input) {
- let target = Number(input[0]);
- let i = 1;
- let command = input[i];
- i++;
- let total = 0;
- while (true) {
- if (command === "closed") {
- break;
- }
- if (total >= target) {
- break;
- }
- if (command === "haircut") {
- command = input[i];
- i++;
- if (command === "mens") {
- total += 15;
- } else if (command === "ladies") {
- total += 20;
- } else if (command === "kids") {
- total += 10;
- }
- }
- if (command === "color") {
- command = input[i];
- i++;
- if (command === "touch up") {
- total += 20;
- } else if (command === "full color") {
- total += 30;
- }
- }
- command = input[i];
- i++;
- }
- if (total >= target) {
- console.log(`You have reached your target for the day!`);
- console.log(`Earned money: ${total}lv.`);
- } else {
- console.log(`Target not reached! You need ${target - total}lv. more.`);
- console.log(`Earned money: ${total}lv.`);
- }
- }
- // hairSalon(["300",
- // "haircut",
- // "ladies",
- // "haircut",
- // "kids",
- // "color",
- // "touch up",
- // "closed"])
- hairSalon(["50",
- "color",
- "full color",
- "haircut",
- "ladies"])
Add Comment
Please, Sign In to add comment