The code
"use strict";
// Create a secretWord variable
let secretWord = "kelkaposzta";
// Make an array containing every letter of the secret word
const secretWordLettersArray = secretWord.split("");
let blanksArray = [];
// Make an array with '_'-s times the letters of the secret word characters.
for (let i = 0; i < secretWord.length; i++) {
blanksArray.push("_");
}
// user guesses a letter
let userGuess = "a";
// If usrGuess is in secretwordArray, change \_ on the same position in blanksArray
for (let i = 0; i < secretWord.length; i++) {
if (secretWordLettersArray[i] == userGuess) {
console.log("Good guess");
blanksArray[i] = userGuess;
console.log(blanksArray);
} else {
console.log("It is not a good guess.");
}
}
This Vscode extension is great to do the job:
GitHub Markdown Preview