Skip to content

Instantly share code, notes, and snippets.

@sccheruku
Created March 14, 2016 16:42
Show Gist options
  • Save sccheruku/70bad9d4bb83a4d7051c to your computer and use it in GitHub Desktop.
Save sccheruku/70bad9d4bb83a4d7051c to your computer and use it in GitHub Desktop.
rock paper scissors
var choices = [{choice: "r", beats: "s", losesTo: "p"},
{choice: "p", beats: "r", losesTo: "s"},
{choice: "s", beats: "p", losesTo: "r"}];
function rps(c){
var i = Math.floor(Math.random() * 3)
var myC = choices[i];
if (myC.choice == c) return "Draw";
else if (myC.beats == c) return "Win";
else if (myC.losesTo == c) return "Lose";
return "error";
}
console.log(rps("s"));
console.log(rps("p"));
console.log(rps("r"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment