Skip to content

Instantly share code, notes, and snippets.

@master5o1

master5o1/hangman.js

Created Apr 22, 2015
Embed
What would you like to do?
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