Spocoman

Easter Eggs Battle

Feb 21st, 2022 (edited)
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function easterEggsBattle(input) {
  2.     let firstPlayer = Number(input.shift());
  3.     let secondPlayer = Number(input.shift());
  4.     let command = input.shift();
  5.  
  6.     while (command !== 'End') {
  7.         if (command === 'one') {
  8.             secondPlayer--;
  9.             if (secondPlayer == 0) {
  10.                 console.log(`Player two is out of eggs. Player one has ${firstPlayer} eggs left.`);
  11.                 break;
  12.             }
  13.         } else if (command === 'two') {
  14.             firstPlayer--;
  15.             if (firstPlayer == 0) {
  16.                 console.log(`Player one is out of eggs. Player two has ${secondPlayer} eggs left.`);
  17.                 break;
  18.             }
  19.         }
  20.         command = input.shift();
  21.     }
  22.  
  23.     if (command === 'End') {
  24.         console.log(`Player one has ${firstPlayer} eggs left.`);
  25.         console.log(`Player two has ${secondPlayer} eggs left.`);
  26.     }
  27. }
Add Comment
Please, Sign In to add comment