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