shan
shan

Reputation: 21

For a wordle clone on code.org, how can I make it so that words that are in the right spot/in the word turn yellow?

So I am making a wordle clone in code.org using the dataset, yet I am facing two issues.

The first issue is that when I console.log the correct answer, sometimes it says "null" and other times it works without issue.

The second problem is I don't know how to make the words yellow if they are out of order or in the word. My code is down below.

//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[index]) {
              setProperty(letters[i], "background-color", "green");
            } else if ((answers[index].includes(guess))) {
              setProperty(letters[i], "background-color", "yellow");
            } else {
              setProperty(letters[i], "background-color", "red");
            }
        setProperty(letters[i], "text", guess[i]);
      }
    });

Specifically the else if statement, and the first four lines of code that are my variables

Upvotes: 1

Views: 1184

Answers (2)

David
David

Reputation: 1

I'm doing the same. To solve this, I had to go through my list of words and remove all of the null values.

https://studio.code.org/projects/applab/LfSkmeCUiI6xCXB6irbhinDSgOoviQdgOhsY48hD_aU

Upvotes: 0

Morgan
Morgan

Reputation: 1

I can answer the first one. The correct answer Wordle data set on code.org contains a null values past 2038, so instead my code for picking a random correct answer looks like this:

var correctAnswerList = getColumn("Wordle", "validWordleAnswer");
function pickWord() {
 randomWord = randomNumber(0,2038 );
 correctAnswer = correctAnswerList[randomWord];

If you figure out how to get letters to turn yellow please share!

Upvotes: 0

Related Questions