hangman.js
2015-04-22 23:14
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'));