允许更大的词语被接受

时间:2022-12-13 21:46:15

I am creating a spelling game for children where empty spaces are highlighted in a grid and clues are given to spell the word correctly by dragging the corresponding letters on the side of the grid.

我正在为儿童创建一个拼写游戏,其中空格在网格中突出显示,并且通过拖动网格侧面的相应字母,可以给出正确拼写单词的线索。

If you get the word right the space in the grid fades away with the use of "wordglow2". If you get it wrong it glows red with "wordglow4".

如果你说得对,那么网格中的空间会因使用“wordglow2”而消失。如果你弄错了它会发出“wordglow4”的红色。

This works fine for 3 letter words as I thought these where going to be theonly words I was ever going to use in my grid. Now I have been told it needs to be expanded it some point and when I add bigger words the script acknowledges them after 3 dropped letters, even if it is 5 long.

这适用于3个字母的单词,因为我认为这些将成为我将要在我的网格中使用的唯一单词。现在我被告知它需要扩展它的某些点,当我添加更大的单词时,脚本会在3个掉落的字母后确认它们,即使它是5长。

Here is the code that currently says if (word == 3) then apply styles...

这是当前所说的代码if(word == 3)然后应用样式...

            if (guesses[word].length == 3) {
            if (guesses[word].join('') == word) {

                $('td[data-word=' + word + ']').addClass('wordglow2');
                $(right).val('Right!');
                $(right).show();
                audioS.play();
                $('.counter').html(completeWords + '/6').show();
                $(wrong).hide();
                $('.minibutton').prop('disabled', false);

I need it to take into consideration, the size of the word and then if it is right do the rest.

我需要考虑到这个词的大小,然后如果它是正确的,那么其余的。

http://jsfiddle.net/smilburn/cTGGA/20/

1 个解决方案

#1


1  

If I understand your question right, you could check the array length against the length of the word. For example:

如果我理解你的问题,你可以根据单词的长度检查数组长度。例如:

if (guesses[word].length == word.length) {

This would validate that the length of the guesses array was the same as the length of the word they are trying to solve, regardless of whether the word has 3, 4, 5, or more letters.

这将验证猜测数组的长度与他们试图解决的单词的长度相同,无论该单词是否具有3,4,5或更多字母。

#1


1  

If I understand your question right, you could check the array length against the length of the word. For example:

如果我理解你的问题,你可以根据单词的长度检查数组长度。例如:

if (guesses[word].length == word.length) {

This would validate that the length of the guesses array was the same as the length of the word they are trying to solve, regardless of whether the word has 3, 4, 5, or more letters.

这将验证猜测数组的长度与他们试图解决的单词的长度相同,无论该单词是否具有3,4,5或更多字母。