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

229
Views
Why won't my wordle clone set the right answer green in code.org?

So I am using the code.org wordle dataset to recreate a wordle clone. The problem is, all the code works fine yet when you input the right answer, it comes out as red (supposed to be green). If someone could take a look at my code and see what is wrong that would be greatly appreciated.

//Getting Wordle Answer 
var answers = getColumn("Wordle", "validWordleAnswer");
var index = (randomNumber(0, answers.length));
console.log(answers[index]);
var letters =  ["letter1", "letter2", "letter3", "letter4", "letter5"];


//Checking Words
onEvent("wordbutton", "click", function( ) {
  var guess = getProperty("wordInput", "text");
  for (var i = 0; i < 5; i++) {
    if (guess == answers) {
      setProperty(letters[i], "background-color", "green");
    } else  {
      setProperty(letters[i], "background-color", "red");
    }
    setProperty(letters[i], "text", guess[i]);
    setProperty("wordsUsedOuput", "text", guess[i]);
  }
});

Specifically line 5 and 6, confused as to what the problem is.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I would expect getColumn to assign an array with multiple results to answers.

Your wordbutton event is comparing that array to guess, which is a string. So, the line if (guess == answers) { is likely a bug. Perhaps you meant, if (guess == answers[index]) {?

Also, you're coloring the whole word red or green based on the answer. If your intent is to check a letter at a time, your code might look a little more like:

let answer=answers[index];
if (guess.charAt(i) == answer.charAt(i)) {
    ...
}
about 4 years ago · Juan Pablo Isaza Report
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!