Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input){
- let playerOne = input.shift();
- let playerTwo = input.shift();
- let command = input.shift();
- let pointsPlayerOne = 0;
- let pointsPlayerTwo = 0;
- while (command != "End of game"){
- let cardPlayerOne = input.shift();
- let cardPlayerTwo = input.shift();
- if(cardPlayerOne > cardPlayerTwo){
- pointsPlayerOne += cardPlayerOne - cardPlayerTwo;
- } else if(cardPlayerOne < cardPlayerTwo){
- pointsPlayerTwo += cardPlayerTwo - cardPlayerOne;
- } else if(cardPlayerOne = cardPlayerTwo) {
- command = input.shift();
- if(cardPlayerOne > cardPlayerTwo){
- console.log(`Number wars!`);
- console.log(`${playerOne} is winner with ${ cardPlayerOne - cardPlayerTwo} points.`);
- break;
- } else if(cardPlayerOne < cardPlayerTwo) {
- console.log(`Number wars!`);
- console.log(`${playerTwo} id winner with ${cardPlayerTwo - cardPlayerOne} points.`);
- break;
- }
- }
- command = input.shift();
- }
- if(command === 'End of game') {
- console.log(`${playerOne} has ${pointsPlayerOne} points.`);
- console.log(`${playerTwo} has ${pointsPlayerTwo} points.`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement