Advertisement
Liliana797979

vqrno reshenie na easter shop

Jan 1st, 2021
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.      
  2. function easterShop(...input) {
  3.     let index = 0;
  4.     let eggsNumber = Number(input[index++]);
  5.     let command = input[index++];
  6.  
  7.     let soldEggs = 0;
  8.  
  9.     while (command !== 'Close') {
  10.         let currentEggasNum = Number(input[index++]);
  11.  
  12.         if (command === "Buy" && currentEggasNum > eggsNumber) {
  13.             console.log('Not enough eggs in store!');
  14.             console.log(`You can buy only ${eggsNumber}.`);
  15.             break;
  16.         } else if (command === "Fill") {
  17.             eggsNumber += currentEggasNum;
  18.  
  19.         } else if (command === "Buy" && currentEggasNum <= eggsNumber) {
  20.             eggsNumber -= currentEggasNum;
  21.             soldEggs += currentEggasNum;
  22.         }
  23.         command = input[index++];
  24.     }
  25.     if (command === 'Close') {
  26.         console.log('Store is closed!');
  27.         console.log(`${soldEggs} eggs sold.`);
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement