Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

199
Vistas
How can I create a dynamic variable within a for loop that adds a new user inputted word?
const listOfWords = ['angel', 'break', 'clear', 'knock', 'maybe'];

var userWord = readLine("Enter a 5 letter word: \n");

var randomItem = listOfWords[Math.floor(Math.random()*listOfWords.length)];

var newWord = userWord;

wordle();


function wordle(){
    letterChecker()
for(var i = 0; i < 5; ++i){
    var inputWord = readLine("Enter a new word: \n");
    letterChecker();
    
    
    
}
    
}

function letterChecker() {
    println(randomItem);
    for(var i = 0; i < 5; i++){
        
        if(newWord[i] === randomItem[i]) {
                console.log(newWord[i] + " is green");
        } else {
            if(randomItem.includes(newWord[i])){
                console.log(newWord[i] + " is yellow");
            }
        }
        if(!randomItem.includes(newWord[i])){
                console.log(newWord[i] + " is grey");
        }
    }
    
    

}

I understand that this is needs to be a more complicated dynamic variable within the for loop, however I don't understand how to make the letterChecker() function also then check up to five new instances of var inputWord. For context this is a wordle game and the outcome I get now is the program running only for one word regardless if a new word is declared within the readLine prompt.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda