Skip to content

Instantly share code, notes, and snippets.

@jasongorman

jasongorman/game.js Secret

Created Apr 3, 2020
Embed
What would you like to do?
const rock = "rock";
const scissors = "scissors";
const paper = "paper";
function play(game, player1, player2) {
let score = {...game.score};
let winner = undefined;
if (player1 === rock) {
if (player2 === scissors) {
score.player1++;
} else {
if (player2 === paper) {
score.player2++;
}
}
}
if (player1 === paper) {
if (player2 === rock) {
score.player1++;
} else {
if (player2 === scissors) {
score.player2++;
}
}
}
if (player1 === scissors) {
if (player2 === paper) {
score.player1++;
} else {
if (player2 === rock) {
score.player2++;
}
}
}
if (score.player1 === 2) {
winner = 1;
}
if (score.player2 === 2) {
winner = 2;
}
return {winner: winner, score: score};
}
module.exports = {play, rock, paper, scissors};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment