Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function easterShop(...input) {
- let index = 0;
- let eggsNumber = Number(input[index++]);
- let command = input[index++];
- let soldEggs = 0;
- while (command !== 'Close') {
- let currentEggasNum = Number(input[index++]);
- if (command === "Buy" && currentEggasNum > eggsNumber) {
- console.log('Not enough eggs in store!');
- console.log(`You can buy only ${eggsNumber}.`);
- break;
- } else if (command === "Fill") {
- eggsNumber += currentEggasNum;
- } else if (command === "Buy" && currentEggasNum <= eggsNumber) {
- eggsNumber -= currentEggasNum;
- soldEggs += currentEggasNum;
- }
- command = input[index++];
- }
- if (command === 'Close') {
- console.log('Store is closed!');
- console.log(`${soldEggs} eggs sold.`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement