对于 code.org 上的单词克隆,如何才能使位于正确位置/单词中的单词变成黄色?
因此,我正在使用数据集在 code.org 中进行 wordle 克隆,但我面临两个问题。
第一个问题是,当我 console.log 正确的答案时,有时它会显示“null”,有时它会正常工作。
第二个问题是我不知道如果单词顺序不正确或在单词中,如何使单词变黄。我的代码在下面。
//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]);
}
});
特别是 else if 语句,以及前四行代码是我的变量
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可以回答第一个问题。 code.org 上的正确答案 Wordle 数据集包含超过 2038 年的空值,因此我用于选择随机正确答案的代码如下所示:
如果您知道如何让字母变成黄色,请分享!
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:
If you figure out how to get letters to turn yellow please share!
我也在做同样的事情。为了解决这个问题,我必须检查单词列表并删除所有空值。
https://studio.code.org/projects/applab/LfSkmeCUiI6xCXB6irbhinDSgOoviQdgOhsY48hD_aU
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