Last active
August 29, 2015 02:35
-
-
Save kevincolten/d0a646fd06100b307a03 to your computer and use it in GitHub Desktop.
Rock Paper Scissors
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
'use strict'; | |
var prompt = require('prompt'); | |
prompt.start(); | |
function compareHands(hand1, hand2) { | |
if (hand1 === hand2) { | |
return "It's a tie!"; | |
} | |
if (hand1 === 'scissors') { | |
if (hand2 === 'paper') { | |
return 'Player 1 has won!'; | |
} | |
return 'Player 2 has won!'; | |
} | |
if (hand1 === 'rock') { | |
if (hand2 === 'scissors') { | |
return 'Player 1 has won!'; | |
} | |
return 'Player 2 has won!'; | |
} | |
if (hand1 === 'paper') { | |
if (hand2 === 'rock') { | |
return 'Player 1 has won!'; | |
} | |
return 'Player 2 has won!'; | |
} | |
} | |
function getPrompt() { | |
prompt.get(['hand1', 'hand2'], function (error, result) { | |
console.log(compareHands(result.hand1, result.hand2)); | |
getPrompt(); | |
}); | |
} | |
getPrompt(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment