对于 code.org 上的单词克隆,如何才能使位于正确位置/单词中的单词变成黄色?

发布于 2025-01-16 04:45:00 字数 1029 浏览 2 评论 0原文

因此,我正在使用数据集在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

红衣飘飘貌似仙 2025-01-23 04:45:00

我可以回答第一个问题。 code.org 上的正确答案 Wordle 数据集包含超过 2038 年的空值,因此我用于选择随机正确答案的代码如下所示:

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

如果您知道如何让字母变成黄色,请分享!

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!

锦欢 2025-01-23 04:45:00

我也在做同样的事情。为了解决这个问题,我必须检查单词列表并删除所有空值。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文