Accepting the animation

前端 未结 2 797
后悔当初
后悔当初 2021-02-07 22:10

EDIT**

In my word game there is a grid with 3 letter words.

The aim of the game is to spell the words by clicking on the corresponding letters

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-07 22:30

    If I understand the question, you are looking for a way to check the validity of a word that is created by selecting letters, and then applying styles to the word.

    Heres what I would do:

    var dict = []; // Create an array with all of the possible words
    var word = "";
    
    function createWord(){ // Creates the variable word to be checked against array
      var addToWord = $(this).html(); // Sets the variable addTo Word to the letter selected
      word = word + addToWord; // Adds the selected letter to the current word
    };
    
    function checkWord(){
      var i = dict[].length; // Sets incrementor "i" to the length of the array
      while (i){  // While "i" is a positive value
        if (word == dict[i]){ // Checks if the word is equal to the word in that spot of the array
          // If it is, apply the correct styles
        }
        else{ // If it isn't, 
          // Do Nothing
        }
       i = i--; // Decrease i by one, and repeat until the whole array has been checked
      }
    };
    
    $('foo bar').click(function(){
      createWord();
      checkWord();
    }
    

    Good Luck! Hope this helps.

    -Brian

提交回复
热议问题