Last active
January 20, 2020 16:44
-
-
Save MartinMuzatko/02e67ea8b67074f8915480436c48b9f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const WIN = 1 | |
const LOSE = -1 | |
const TIE = 0 | |
const methods = ['rock', 'paper', 'scissor'] | |
let score = 0 | |
const gameMap = new Map([ | |
['rock-paper', LOSE], | |
['rock-scissor', WIN], | |
['rock-rock', TIE], | |
['paper-paper', TIE], | |
['paper-scissor', LOSE], | |
['paper-rock', WIN], | |
['scissor-paper', WIN], | |
['scissor-scissor', TIE], | |
['scissor-rock', LOSE], | |
]) | |
const randomItem = items => items[Math.random() * items.length | 0] | |
const getResult = player => { | |
const enemy = randomItem(methods) | |
return gameMap.get(`${player}-${enemy}`) | |
} | |
score += getResult('scissor') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment