Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function easterEggsBattle(input) {
- let firstPlayer = Number(input.shift());
- let secondPlayer = Number(input.shift());
- let command = input.shift();
- while (command !== 'End') {
- if (command === 'one') {
- secondPlayer--;
- if (secondPlayer == 0) {
- console.log(`Player two is out of eggs. Player one has ${firstPlayer} eggs left.`);
- break;
- }
- } else if (command === 'two') {
- firstPlayer--;
- if (firstPlayer == 0) {
- console.log(`Player one is out of eggs. Player two has ${secondPlayer} eggs left.`);
- break;
- }
- }
- command = input.shift();
- }
- if (command === 'End') {
- console.log(`Player one has ${firstPlayer} eggs left.`);
- console.log(`Player two has ${secondPlayer} eggs left.`);
- }
- }
Add Comment
Please, Sign In to add comment