Advertisement
Liliana797979

excursion sale vqrno reshenie

Dec 19th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function excursionSale(input) {
  2.     let excursionSeaCount = Number(input.shift());
  3.     let excursionMountainCount = Number(input.shift());
  4.     let profit = 0;
  5.     const prices = {
  6.         "sea":680,
  7.         "mountain":499,
  8.     }
  9.  
  10.     while (input.length > 0) {
  11.         const destination = input.shift();
  12.         if (destination === "Stop" || (excursionMountainCount === 0 && excursionSeaCount === 0)) {
  13.             break;
  14.         }
  15.         if (destination.toLower.Case() === "sea" && excursionSeaCount > 0) {
  16.             profit += prices.sea;
  17.             excursionSeaCount--;
  18.         } else if (destination.toLower.Case() === "mountain" && excursionMountainCount > 0) {
  19.             profit += prices.mountain;
  20.             excursionMountainCount--;
  21.         }
  22.     }
  23.  
  24.     if (excursionMountainCount === 0 && excursionSeaCount === 0) {
  25.         console.log(`Good job! Everything is sold.`);
  26.     }
  27.     console.log(`Profit: ${profit} leva.`);
  28. }
  29.  
  30. excursionSale(["2", "2", "mountain", "sea", "sea", "mountain"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement