Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!