I'm trying to make a function which takes a random word and then splits the word into individual letters, then replace the letters with different characters to hide the word.
This is what I thought of originally, but does not work at all (selectWord and answer are both declared outside of all functions):
function word() {
selectWord = answer.split('').map(letter , " _ ").join('');
document.getElementById('correct-word').innerHTML = selectWord;}
Any input would be greatly appreciated :)
CodePudding user response:
function word() {
selectWord = answer.split('').map(() => " _ ")).join('');
document.getElementById('correct-word').innerHTML = selectWord;
}
CodePudding user response:
Map takes a function.
selectWord = answer.split('').map(letter=> " _ ").join('');