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