Skip to content

Instantly share code, notes, and snippets.

@winnekes
Created November 21, 2019 18:18
Show Gist options
  • Save winnekes/e4c913230c7a38de63e14ca90f9a712f to your computer and use it in GitHub Desktop.
Save winnekes/e4c913230c7a38de63e14ca90f9a712f to your computer and use it in GitHub Desktop.
if (user1.choice !== 'no choice' && user2.choice !== 'no choice') {
if (user1.choice === user2.choice) {
updatedRoom = await room.update({
status: 'game is over',
winner: `oh, it's a tie!`,
});
} else {
if (user1.choice === ROCK) {
if (user2.choice === SCISSORS) {
updatedRoom = await room.update({
status: 'game is over',
winner: user1.username,
});
const winnerGetsPoints = await user1.increment(
'points'
);
}
} else {
updatedRoom = await room.update({
status: 'game is over',
winner: user2.username,
});
const winnerGetsPoints = await user2.increment('points');
}
if (user1.choice === SCISSORS) {
if (user2.choice === PAPER) {
updatedRoom = await room.update({
status: 'game is over',
winner: user1.username,
});
const winnerGetsPoints = await user1.increment(
'points'
);
}
} else {
updatedRoom = await room.update({
status: 'game is over',
winner: user2.username,
});
const winnerGetsPoints = await user2.increment('points');
}
if (user1.choice === PAPER) {
if (user2.choice === SCISSORS) {
updatedRoom = await room.update({
status: 'game is over',
winner: user2.username,
});
const winnerGetsPoints = await user2.increment(
'points'
);
}
} else {
updatedRoom = await room.update({
status: 'game is over',
winner: user1.username,
});
const winnerGetsPoints = await user1.increment('points');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment