I’m developing a word guessing game in JavaScript and I have code similar to the following:
function intentar() {
const INTENTO = leerIntento();
if (INTENTO === palabra ) {
terminar ("<h1>GANASTE!</h1>")
return
}
for (let i in palabra) {
if (INTENTO[i]===palabra[i]) {
console.log(INTENTO[i], "VERDE")
} else if( palabra.includes(INTENTO[i]) ) {
console.log(INTENTO[i], "AMARILLO")
} else {
console.log(INTENTO[i], "GRIS")
}
}
intentos--
if (intentos==0){
terminar("<h1>PERDISTE!</h1>")
}
}
How do I implement the read Intent function to get user input?
Is there a more efficient way to check if the user’s intent matches the secret word?
How can I improve the readability and maintainability of my code?
I would appreciate any guidance or advice to optimize my implementation of the word guessing game in JavaScript. Thank you!