Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function easterEggsBattle(input) {
- let firstPlayerEggs = Number(input[0]);
- let secondPlayerEggs = Number(input[1]);
- let index = 2;
- let command = input[index];
- index++;
- while (command !== "End") {
- if (command === "one") {
- secondPlayerEggs--;
- } else {
- firstPlayerEggs--;
- }
- if (firstPlayerEggs === 0) {
- console.log(`Player one is out of eggs. Player two has ${secondPlayerEggs} eggs left.`);
- break;
- } else if (secondPlayerEggs === 0) {
- console.log(`Player two is out of eggs. Player one has ${firstPlayerEggs} eggs left.`);
- break;
- }
- command = input[index];
- index++;
- }
- if (command === "End") {
- console.log(`Player one has ${firstPlayerEggs} eggs left.`);
- console.log(`Player two has ${secondPlayerEggs} eggs left.`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment