Advertisement
EntropyStarRover

Number wars

Mar 13th, 2019
135
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function numberWars(input){
  2.     let player1=input.shift();
  3.     let player2=input.shift();
  4.     let command=input.shift();
  5.  
  6.     let playerOnePoints=0;
  7.     let playerTwoPoints=0;
  8.  
  9.     let voina=false;
  10.  
  11.     while (command!="End of game"){
  12.    
  13.         let playerOnecard=Number(command);
  14.      
  15.         let playerTwocard=Number(input.shift());
  16.      
  17.         if (playerOnecard>playerTwocard){
  18.             playerOnePoints+=playerOnecard-playerTwocard;
  19.        
  20.         } else if (playerTwocard>playerOnecard){
  21.             playerTwoPoints+=playerTwocard-playerOnecard;
  22.          
  23.         } else if (playerOnecard==playerTwocard){
  24.             console.log(`Number wars!`);
  25.             playerOnecard=Number(input.shift());
  26.                     playerTwocard=Number(input.shift());
  27.            
  28.                     if (playerOnecard>playerTwocard){
  29.                
  30.                 console.log(`${player1} is winner with ${playerOnePoints} points`);
  31.                 return;
  32.                
  33.             } else if (playerOnecard<playerTwocard){
  34.              
  35.                 console.log(`${player2} is winner with ${playerTwoPoints} points`);
  36.                 return;
  37.                
  38.         }
  39.        
  40.     }
  41.     command=input.shift();
  42.  
  43.     }
  44.  console.log(`${player1} has ${playerOnePoints} points`);
  45.  console.log(`${player2} has ${playerTwoPoints} points`);
  46.        
  47.    
  48. }
Advertisement
RAW Paste Data Copied
Advertisement