Skip to content

Instantly share code, notes, and snippets.

@kevincolten
Last active August 29, 2015 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevincolten/d0a646fd06100b307a03 to your computer and use it in GitHub Desktop.
Save kevincolten/d0a646fd06100b307a03 to your computer and use it in GitHub Desktop.
Rock Paper Scissors
'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