Guest User

Game Number Wars - Softuni - 50/100 in Judge

a guest
Apr 4th, 2019
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function numberWars(input) {
  2.     let playerOneName = input.shift();
  3.     let playerTwoName = input.shift();
  4.     let playerOnePoints = input.shift();
  5.     let playerTwoPoints = Number(input.shift());
  6.     let playerOneSumPoints = 0;
  7.     let playerTwoSumPoints = 0;
  8.  
  9.     while (playerOnePoints != 'End of game') {
  10.         playerOnePoints = Number(playerOnePoints);
  11.         if (playerOnePoints > playerTwoPoints) {
  12.             playerOneSumPoints += playerOnePoints - playerTwoPoints;
  13.         } else if (playerTwoPoints > playerOnePoints) {
  14.             playerTwoSumPoints += playerTwoPoints - playerOnePoints;
  15.         } else {
  16.             playerOnePoints = Number(input.shift());
  17.             playerTwoPoints = Number(input.shift());
  18.             if (playerOneSumPoints > playerTwoSumPoints) {
  19.                 console.log(`Number wars!`);
  20.                 console.log(`${playerOneName} is winner with ${playerOneSumPoints} points`);
  21.                 break;
  22.             } else if (playerTwoSumPoints > playerOneSumPoints) {
  23.                 console.log(`Number wars!`);
  24.                 console.log(`${playerTwoName} is winner with ${playerTwoSumPoints} points`);
  25.                 break;
  26.             }
  27.         }
  28.         playerOnePoints = input.shift();
  29.         playerTwoPoints = Number(input.shift());
  30.     }
  31.     console.log(`${playerOneName} has ${playerOneSumPoints} points`);
  32.     console.log(`${playerTwoName} has ${playerTwoSumPoints} points`);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment