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