I'm building a word game. One of the functions I need is a function that receives a word and replaces several words with (_) and gives the incomplete word as output. I want the number of words to be replaced and the location of those words to be chosen randomly. The code I wrote, although it uses for, is only able to replace one word. What changes should I make in the for part of the code that has the ability to move several words? for example : "laptop" => "l_pt_p"
function wordToIncomplete(word) {
let randomNumber = Math.floor(Math.random() * 3) + 1
let _randomNumber = Math.floor(Math.random() * word.length)
let _word = "";
for (let index = 0; index < randomNumber; index++) {
_word = word.replace(word[_randomNumber], '_');
}
return _word
}