Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function gameNumberWars(input) {
- let player1 = input.shift();
- let player2 = input.shift();
- let command = input.shift();
- let point1 = 0;
- let point2 = 0;
- while (command !== "End of game") {
- let card01 = Number(command);
- let card02 = Number(input.shift());
- if (card01 > card02) {
- point1 += card01 - card02;
- } else if (card01 < card02) {
- point2 += card02 - card01;
- } else {
- card01 = Number(input.shift());
- card02 = Number(input.shift());
- console.log("Number wars!")
- if (card01 > card02) {
- console.log(`${player1} is winner with ${point1} points`);
- } else {
- console.log(`${player2} is winner with ${point2} points`);
- }
- break;
- }
- command = input.shift();
- }
- if (command === "End of game") {
- console.log(`${player1} has ${point1} points`);
- console.log(`${player2} has ${point2} points`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement