Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function excursionSale(input) {
- let excursionSeaCount = Number(input.shift());
- let excursionMountainCount = Number(input.shift());
- let profit = 0;
- const prices = {
- "sea":680,
- "mountain":499,
- }
- while (input.length > 0) {
- const destination = input.shift();
- if (destination === "Stop" || (excursionMountainCount === 0 && excursionSeaCount === 0)) {
- break;
- }
- if (destination.toLower.Case() === "sea" && excursionSeaCount > 0) {
- profit += prices.sea;
- excursionSeaCount--;
- } else if (destination.toLower.Case() === "mountain" && excursionMountainCount > 0) {
- profit += prices.mountain;
- excursionMountainCount--;
- }
- }
- if (excursionMountainCount === 0 && excursionSeaCount === 0) {
- console.log(`Good job! Everything is sold.`);
- }
- console.log(`Profit: ${profit} leva.`);
- }
- excursionSale(["2", "2", "mountain", "sea", "sea", "mountain"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement