Last active
June 22, 2020 17:20
-
-
Save Genyus/5e72458d2f7b9d8e002eb12f6a8e0547 to your computer and use it in GitHub Desktop.
JS snippet demonstrating code refactoring
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
function isMatch(computerChoice, playerChoice, option1, option2) { | |
return computerChoice === option1 && playerChoice === option2 || computerChoice === option2 && playerChoice === option1; | |
} | |
if (computer.currentChoice == player.currentChoice) { | |
console.log("It's a tie!"); | |
} | |
else if (isMatch(computer.currentChoice, player.currentChoice, gameOptions[1], gameOptions[2]) { | |
console.log("Scalpellus wins!"); | |
} | |
else if (isMatch(computer.currentChoice, player.currentChoice, gameOptions[0], gameOptions[2]) { | |
console.log("Lapis wins!"); | |
} | |
else if (isMatch(computer.currentChoice, player.currentChoice, gameOptions[1], gameOptions[0]) { | |
console.log("Papyrus wins!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment