Skip to content

Instantly share code, notes, and snippets.

@jason-s13r
Created April 22, 2015 23:14
Show Gist options
  • Save jason-s13r/d75343d1a8f7761212f6 to your computer and use it in GitHub Desktop.
Save jason-s13r/d75343d1a8f7761212f6 to your computer and use it in GitHub Desktop.
function hangman(word) {
var reference = word.replace(/[a-zA-Z]/g,'-');
function reveal(letter) {
reference = reference.split('').map(function(v, i){
return word[i] === letter ? letter : v;
}).join('');
return reference;
};
return {
reveal: reveal
};
}
var game = hangman('carrot');
console.log(game.reveal('r'));
console.log(game.reveal('a'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment