Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let eggsInShop = Number(input.shift());
- let command = input.shift();
- let buyOrFill = 0;
- while (command === 'Buy' || command === 'Fill') {
- if (command === 'Buy') {
- buyOrFill = Number(input.shift());
- if (eggsInShop < buyOrFill) {
- console.log(`Not enough eggs in store!`)
- console.log(`You can buy only ${eggsInShop}.`)
- break;
- }
- eggsInShop -= buyOrFill
- command = input.shift();
- } else if (command === 'Fill') {
- buyOrFill = Number(input.shift());
- eggsInShop += buyOrFill
- command = input.shift();
- }
- }
- if (command === 'Close') {
- console.log(`Store is closed!`)
- console.log(`${eggsInShop + buyOrFill} eggs sold.`)
- }
- }
- solve(
- [
- '13', 'Buy',
- '8', 'Fill',
- '3', 'Buy',
- '10'
- ]
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement