Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let initiallyEgs = Number(input.shift());
- let comand;
- let isOver = false;
- let lessEgs = 0;
- let soldEgs = 0;
- while (comand !== 'Close') {
- if (comand == "Buy") {
- let egs = Number(input.shift());
- initiallyEgs -= egs;
- if(initiallyEgs<=0){
- isOver = true;
- break;
- }
- soldEgs += egs;
- } else if (comand == "Fill") {
- let egs = Number(input.shift());
- initiallyEgs += egs;
- lessEgs = initiallyEgs;
- }
- comand = input.shift();
- }
- if (isOver) {
- console.log(`Not enough eggs in store!`);
- console.log(`You can buy only ${lessEgs}.`);
- } else {
- console.log(`Store is closed!`);
- console.log(`${soldEgs} eggs sold.`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement