I am currently working on a Wordle-style game with a 6x6 grid. I'm sending the row as an array through a socket, and while I can check if a letter is correct, I'm having trouble with identifying duplicates that are in the wrong position. I iterate through the array to compare letters and their positions, but the verification process isn't working as expected. The word for this game is "cancer," and I've provided the code below. Any assistance would be greatly appreciated.
dupCheck == wordPoint
socket.on('check wordle', (check) => {
var word = "cancer";
var feedback = [];
console.log(check)
for(var i = 0; i < check.length; i++)
{
var letter = check[i];
var wordPoint = word.substring(i, i+1);
if(word.includes(letter))
{
if(letter == wordPoint)
{
feedback.push("green");
}
else
{
var duplicate = false;
for(var j = i; j < check.length; j++)
{
var dupCheck = check[j];
console.log(dupCheck + " j " + wordPoint)
if(dupCheck == wordPoint)
{
duplicate = true;
console.log(j)
console.log("j")
break
}
else
{
console.log("It reads this")
}
console.log(duplicate)
}
for(var k = 0; k < i; k++)
{
var dupCheck = check[k];
console.log(dupCheck + " k " + wordPoint)
if(dupCheck == wordPoint)
{
duplicate = true;
console.log(k)
console.log("k")
break
}
}
if(duplicate)
{
feedback.push("grey");
}
else
{
feedback.push("yellow");
}
}
}
else
{
feedback.push("grey");
}
}
console.log(feedback)
io.emit('wordle feedback', feedback);
})
During testing in the console output, I notice that the two values are indeed identical.