Create a single function (the skeleton has been provided for you). The function must be capable of 'playing' a single round of the classic game 'Rock, Paper, Scissors':
Rock beats Scissors, Scissors beats paper, Paper beats rock
When called, the function should return the winning player reference (i.e., 'player1' or 'player2' or 'draw') as a single string.
Evidence of testing is expected. You should test your solution by making sufficient calls to your function so that you are positive that it works as expected. These should be left at the bottom of rps.js
commented out.
Your final version should demonstrate evidence of being refactored; please note, refactoring is not bug-fixing - essentially it is reducing complexity and simplifying your codebase such that it is as efficient, readable, structured and as manageable as possible.
Some example calls to the function:
rock_paper_scissors("paper", "paper") # should return "draw"
rock_paper_scissors("scissors", "paper") # should return "player1"
rock_paper_scissors("paper", "scissors") # should return "player2"
Once you have the basic version working, extend your function so that it supports Sheldon Cooper's 'Big Bang' version 'Rock, Paper, Scissors, Lizard, Spock'. Remember to write the tests!
Prior to actually submitting your final attempt you should ensure you have reviewed and considered the following checklist.
- Refactored
rock_paper_scissors
function. - Does your solution follow accepted coding conventions?
- Your 'test' code, commented out at the bottom of
rps.js