kandi background
Explore Kits

wordgame | simple word game built using WebSockets

 by   shekhargulati Java Version: Current License: No License

 by   shekhargulati Java Version: Current License: No License

Download this library from

kandi X-RAY | wordgame Summary

wordgame is a Java library. wordgame has no bugs, it has no vulnerabilities, it has build file available and it has low support. You can download it from GitHub.
A simple word game built using WebSockets. The app uses JSR356 API.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • wordgame has a low active ecosystem.
  • It has 25 star(s) with 37 fork(s). There are 6 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 1 open issues and 0 have been closed. On average issues are closed in 1144 days. There are no pull requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of wordgame is current.
wordgame Support
Best in #Java
Average in #Java
wordgame Support
Best in #Java
Average in #Java

quality kandi Quality

  • wordgame has 0 bugs and 0 code smells.
wordgame Quality
Best in #Java
Average in #Java
wordgame Quality
Best in #Java
Average in #Java

securitySecurity

  • wordgame has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • wordgame code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
wordgame Security
Best in #Java
Average in #Java
wordgame Security
Best in #Java
Average in #Java

license License

  • wordgame does not have a standard license declared.
  • Check the repository for any license declaration and review the terms closely.
  • Without a license, all rights are reserved, and you cannot use the library in your applications.
wordgame License
Best in #Java
Average in #Java
wordgame License
Best in #Java
Average in #Java

buildReuse

  • wordgame releases are not available. You will need to build from source code and install.
  • Build file is available. You can build the component from source.
  • It has 269 lines of code, 20 functions and 6 files.
  • It has medium code complexity. Code complexity directly impacts maintainability of the code.
wordgame Reuse
Best in #Java
Average in #Java
wordgame Reuse
Best in #Java
Average in #Java
Top functions reviewed by kandi - BETA

kandi has reviewed wordgame and discovered the below as its top functions. This is intended to give you an instant insight into wordgame implemented functionality, and help decide if they suit your requirements.

  • On a message handler .
    • Returns true if this word equals another word .
      • Checks for the next word and returns the next word .
        • Starts a webgame server .
          • Entry point to the game server .
            • Initializes a session .
              • Returns a 128 - bit hash code .
                • Gets the single instance .
                  • Gets a random word .

                    Get all kandi verified functions for this library.

                    Get all kandi verified functions for this library.

                    wordgame Key Features

                    A simple word game built using WebSockets. The app uses JSR356 API

                    React useState not updating

                    copy iconCopydownload iconDownload
                    useEffect(() => {
                             if (word.isGuessed) {
                                 const newWord = getWord();
                                 setWord(newWord);
                                 setRenderedCharacters(newWord.renderedCharacters);
                             }
                    }, [word.isGuessed, renderedCharacters]);
                    
                    
                    const WordFrame = () => {
                        const [word, setWord] = useState(() => new Word('apple'));
                    
                        // ...
                    
                        const keyDownHandler = (e: KeyboardEvent): void => { /* ... */ };
                    
                        useEffect(() => {
                            document.addEventListener('keydown', keyDownHandler);
                            return () => document.removeEventListener('keydown', keyDownHandler);
                        }, [word]); // <-- add `word` to the dependencies for this effect
                    
                        // ...
                    };
                    

                    Print random line from text file in java

                    copy iconCopydownload iconDownload
                    for(int i = 1; i <= wordNumber; i++){
                        String secretWord = wordListNew.nextLine();
                        if (i == wordNumber){
                            System.out.println(secretWord);
                        }
                    }
                    

                    Random value not in the range of array/dictionary

                    copy iconCopydownload iconDownload
                    <html>
                    <head>
                        <title>Aliyah's dictee spel</title>
                        <link rel="stylesheet" type="text/css" href="style.css">
                    </head>
                    <body>
                      <div id="header">
                        <h1>Hej! Velkommen til Aliyahs diktee!</h1>
                      </div>
                      <div id="Random_word">
                        <h2 id="Empty">Click start to start</h2>
                        <button id="startGame">Start</button>
                        <button id="editList">Edit word list</button>
                        <h3 id="correctWord"></h3>
                    
                      </div>
                      <script>
                        function sleep(ms) {
                          return new Promise(resolve => setTimeout(resolve, ms));
                        }
                    
                        var dictionary = [{
                            word: "apple",
                            audio: 'apple.mp3',
                          },
                          {
                            word: "baby",
                            audio: 'baby.mp3',
                          },
                          {
                            word: "car",
                            audio: 'car.mp3'
                          }
                    
                        ];
                    
                        var wordsWrong = [];
                        var wordsCorrectCounter = 0;
                        var wordsWrongCounter = 0;
                        var cheer = new Audio('correct.mp3');
                        var boo = new Audio('wrong.mp3');
                    
                        function editWords() {
                          console.log("under construction");
                        };
                    
                        function startGame() {
                          document.getElementById("startGame").remove();
                          document.getElementById("editList").remove();
                          newWord(dictionary);
                        };
                    
                        async function newWord(dictionary) {
                          if (Object.entries(dictionary).length === 0) {
                            endGame();
                          } else {
                            var random = Math.floor(Math.random() * dictionary.length);
                            console.log(random)
                            document.getElementById("Empty").innerHTML = dictionary[random].word;
                            console.log(dictionary[random].word);
                            console.log(dictionary);
                            await sleep(2000);
                            document.getElementById("Empty").innerHTML = "       ";
                            createInputField(random);
                          }
                        };
                    
                        function createInputField(random) {
                          var entry = document.createElement("input");
                          entry.setAttribute("type", "text");
                          entry.id = "inputfield";
                          document.body.appendChild(entry);
                          let btn = document.createElement("button");
                          btn.id = "okBtn";
                          btn.innerHTML = "ok";
                          btn.type = "submit";
                          btn.name = "answerBtn";
                          document.body.appendChild(btn);
                          document.getElementById("okBtn").addEventListener("click", () => checkAnswer(random, entry.value));
                        };
                    
                        function checkAnswer(random, entry) {
                          var answer = entry.toLowerCase();
                    
                          if (dictionary[random].word == answer) {
                            cheer.play();
                            wordsCorrectCounter += 1;
                            document.getElementById("okBtn").remove();
                            document.getElementById("inputfield").remove();
                            dictionary.splice(random, 1);
                            console.log(dictionary);
                            newWord(dictionary);
                          } else {
                            wordsWrong.push(dictionary[random].word);
                            wordsWrongCounter += 1;
                            document.getElementById("okBtn").remove();
                            document.getElementById("inputfield").remove();
                            boo.play();
                            document.body.style.backgroundColor = "red";
                            document.getElementById("correctWord").innerHTML = dictionary[random].word;
                            let btn = document.createElement("button");
                            btn.id = "contBtn";
                            btn.innerHTML = "Continue";
                            btn.type = "submit";
                            btn.name = "continueBtn";
                            document.body.appendChild(btn);
                            document.getElementById("contBtn").addEventListener("click", () => wrongAnswer(random));
                          }
                        };
                    
                        function wrongAnswer(random) {
                          document.getElementById("contBtn").remove();
                          document.getElementById("correctWord").innerHTML = "    "
                          delete dictionary[random];
                          newWord(dictionary);
                        };
                    
                        function endGame() {
                          document.getElementById("Empty").innerHTML = "you are done!" + "Correct: " + wordsCorrectCounter + "Wrong: " + wordsWrongCounter +
                            "These words were wrong: " + wordsWrong;
                    
                    
                        };
                    
                        function Refresh() {
                          window.parent.location = window.parent.location.href;
                        };
                    
                        document.getElementById("startGame").addEventListener("click", () => startGame());
                      </script>
                    </body>
                    
                    </html>
                    dictionary = [
                        { word: "apple", audio: 'apple.mp3', },
                        { word: "baby", audio: 'baby.mp3', },
                        { word: "car", audio: 'car.mp3' }
                    ];
                    
                    dictionary = [
                        { word: "apple", audio: 'apple.mp3', },
                        { word: "baby", audio: 'baby.mp3', },
                    ];
                    
                    let dictionary = [
                        { word: "apple", audio: 'apple.mp3', },
                        { word: "baby", audio: 'baby.mp3', },
                        { word: "car", audio: 'car.mp3' }
                    ];
                    // only the item that item.word != "apple" will pass this
                    dictionary = dictionary.filter(item => item.word != "apple");
                    
                    console.log(dictionary);
                    let x = "test";
                    console.log(`this is a ${x}`);
                    let dictionary = [
                                { word: "apple", audio: 'apple.mp3', },
                                { word: "baby", audio: 'baby.mp3', },
                                { word: "car", audio: 'car.mp3' }
                            ],
                        target = dictionary.find(item => item.word=="apple"),
                        audio = false;
                    if(target) audio = target.audio;
                    console.log(audio);
                    <html>
                    
                    <head>
                        <title>Aliyah's dictee spel</title>
                        <link rel="stylesheet" type="text/css" href="style.css">
                    </head>
                    
                    <body>
                        <div id="header">
                            <h1>Hej! Velkommen til Aliyahs diktee!</h1>
                        </div>
                        <div id="Random_word">
                            <h2 id="Empty">Click start to start</h2>
                            <button id="startGame">Start</button>
                            <button id="editList">Edit word list</button>
                            <h3 id="correctWord"></h3>
                    
                        </div>
                        <script>
                            function sleep(ms) {
                                return new Promise(resolve => setTimeout(resolve, ms));
                            }
                    
                            var dictionary = [
                                { word: "apple", audio: 'apple.mp3', },
                                { word: "baby", audio: 'baby.mp3', },
                                { word: "car", audio: 'car.mp3' }
                            ];
                    
                            var wordsWrong = [];
                            var wordsCorrectCounter = 0;
                            var wordsWrongCounter = 0;
                            //var cheer = new Audio('correct.mp3');
                            //var boo = new Audio('wrong.mp3');
                    
                            function editWords() {
                                console.log("under construction");
                            }
                    
                            function startGame() {
                                document.getElementById("startGame").remove();
                                document.getElementById("editList").remove();
                                newWord();
                            }
                    
                            // dictionary is global variable, you don't need to pass it to access it
                            async function newWord() {
                    
                                // I add this so the color will be reset after click continue
                                document.body.style.backgroundColor = "";
                    
                                if (Object.entries(dictionary).length === 0) {
                                    endGame();
                                } else {
                                    var random = Math.floor(Math.random() * dictionary.length),
                                        // get the random word here when it still exist in dictionary
                                        random_word = dictionary[random].word;
                    
                                    document.getElementById("Empty").innerHTML = random_word;
                                    console.log(random_word);
                                    console.log(dictionary);
                                    await sleep(2000);
                                    document.getElementById("Empty").innerHTML = "       ";
                    
                                    // direct pass the ramdom word, not the ramdom index
                                    // ramdom index could be invalid after you remove item from dictionary
                                    // which is why you get the error
                                    createInputField(random_word);
                                }
                            }
                    
                            function createInputField(random_word) {
                                var entry = document.createElement("input");
                                entry.setAttribute("type", "text");
                                entry.id = "inputfield";
                                document.body.appendChild(entry);
                                let btn = document.createElement("button");
                                btn.id = "okBtn";
                                btn.innerHTML = "ok";
                                btn.type = "submit";
                                btn.name = "answerBtn";
                                document.body.appendChild(btn);
                                document.getElementById("okBtn").addEventListener("click", () => checkAnswer(random_word, entry.value));
                            }
                    
                            function checkAnswer(random_word, entry) {
                                var answer = entry.toLowerCase();
                    
                                if (random_word == answer) {
                                    //cheer.play();
                    
                                    // if you only need +1, you can use ++
                                    wordsCorrectCounter++;
                    
                                    document.getElementById("okBtn").remove();
                                    document.getElementById("inputfield").remove();
                    
                                    // use Array.filter() to remove random_word(answer) from the dictionary
                                    // only word != random_word will pass
                                    dictionary = dictionary.filter(item => item.word != random_word);
                                    console.log(dictionary);
                                    newWord();
                                } else {
                                    // I didn't see this, so I add it
                                    // if you only need +1, you can use ++
                                    wordsWrongCounter++;
                    
                                    // because we pass the random_word(answer) now, we can just push it
                                    wordsWrong.push(random_word);
                    
                                    document.getElementById("okBtn").remove();
                                    document.getElementById("inputfield").remove();
                                    //boo.play();
                                    document.body.style.backgroundColor = "red";
                                    document.getElementById("correctWord").innerHTML = random_word;
                                    
                                    let btn = document.createElement("button");
                                    btn.id = "contBtn";
                                    btn.innerHTML = "Continue";
                                    btn.type = "submit";
                                    btn.name = "continueBtn";
                                    document.body.appendChild(btn);
                    
                                    document.getElementById("contBtn").addEventListener("click", () => wrongAnswer(random_word));
                                }
                            }
                    
                            function wrongAnswer(random_word) {
                                document.getElementById("contBtn").remove();
                                document.getElementById("correctWord").innerHTML = "    ";
                                // same as above
                                // use Array.filter() to remove correct_word(answer) from the dictionary
                                // only word != correct_word will pass
                                dictionary = dictionary.filter(item => item.word != random_word);
                                newWord();
                            }
                    
                            function endGame() {
                                /*
                                use `` to set string, it more readable & easier to edit
                                you can put variable in it by use ${variable_name}
                    
                                example: 
                                let x = "test";
                                console.log(`this is a ${x}`);
                                
                                result:
                                this is a test
                                */
                                document.getElementById("Empty").innerHTML =
                                    `you are done! Correct: ${wordsCorrectCounter} Wrong: ${wordsWrongCounter} These words were wrong: ${wordsWrong}`;
                            }
                    
                            function Refresh() {
                                window.parent.location = window.parent.location.href;
                            }
                    
                            document.getElementById("startGame").addEventListener("click", () => startGame());
                        </script>
                    </body>
                    
                    </html>
                    dictionary = [
                        { word: "apple", audio: 'apple.mp3', },
                        { word: "baby", audio: 'baby.mp3', },
                        { word: "car", audio: 'car.mp3' }
                    ];
                    
                    dictionary = [
                        { word: "apple", audio: 'apple.mp3', },
                        { word: "baby", audio: 'baby.mp3', },
                    ];
                    
                    let dictionary = [
                        { word: "apple", audio: 'apple.mp3', },
                        { word: "baby", audio: 'baby.mp3', },
                        { word: "car", audio: 'car.mp3' }
                    ];
                    // only the item that item.word != "apple" will pass this
                    dictionary = dictionary.filter(item => item.word != "apple");
                    
                    console.log(dictionary);
                    let x = "test";
                    console.log(`this is a ${x}`);
                    let dictionary = [
                                { word: "apple", audio: 'apple.mp3', },
                                { word: "baby", audio: 'baby.mp3', },
                                { word: "car", audio: 'car.mp3' }
                            ],
                        target = dictionary.find(item => item.word=="apple"),
                        audio = false;
                    if(target) audio = target.audio;
                    console.log(audio);
                    <html>
                    
                    <head>
                        <title>Aliyah's dictee spel</title>
                        <link rel="stylesheet" type="text/css" href="style.css">
                    </head>
                    
                    <body>
                        <div id="header">
                            <h1>Hej! Velkommen til Aliyahs diktee!</h1>
                        </div>
                        <div id="Random_word">
                            <h2 id="Empty">Click start to start</h2>
                            <button id="startGame">Start</button>
                            <button id="editList">Edit word list</button>
                            <h3 id="correctWord"></h3>
                    
                        </div>
                        <script>
                            function sleep(ms) {
                                return new Promise(resolve => setTimeout(resolve, ms));
                            }
                    
                            var dictionary = [
                                { word: "apple", audio: 'apple.mp3', },
                                { word: "baby", audio: 'baby.mp3', },
                                { word: "car", audio: 'car.mp3' }
                            ];
                    
                            var wordsWrong = [];
                            var wordsCorrectCounter = 0;
                            var wordsWrongCounter = 0;
                            //var cheer = new Audio('correct.mp3');
                            //var boo = new Audio('wrong.mp3');
                    
                            function editWords() {
                                console.log("under construction");
                            }
                    
                            function startGame() {
                                document.getElementById("startGame").remove();
                                document.getElementById("editList").remove();
                                newWord();
                            }
                    
                            // dictionary is global variable, you don't need to pass it to access it
                            async function newWord() {
                    
                                // I add this so the color will be reset after click continue
                                document.body.style.backgroundColor = "";
                    
                                if (Object.entries(dictionary).length === 0) {
                                    endGame();
                                } else {
                                    var random = Math.floor(Math.random() * dictionary.length),
                                        // get the random word here when it still exist in dictionary
                                        random_word = dictionary[random].word;
                    
                                    document.getElementById("Empty").innerHTML = random_word;
                                    console.log(random_word);
                                    console.log(dictionary);
                                    await sleep(2000);
                                    document.getElementById("Empty").innerHTML = "       ";
                    
                                    // direct pass the ramdom word, not the ramdom index
                                    // ramdom index could be invalid after you remove item from dictionary
                                    // which is why you get the error
                                    createInputField(random_word);
                                }
                            }
                    
                            function createInputField(random_word) {
                                var entry = document.createElement("input");
                                entry.setAttribute("type", "text");
                                entry.id = "inputfield";
                                document.body.appendChild(entry);
                                let btn = document.createElement("button");
                                btn.id = "okBtn";
                                btn.innerHTML = "ok";
                                btn.type = "submit";
                                btn.name = "answerBtn";
                                document.body.appendChild(btn);
                                document.getElementById("okBtn").addEventListener("click", () => checkAnswer(random_word, entry.value));
                            }
                    
                            function checkAnswer(random_word, entry) {
                                var answer = entry.toLowerCase();
                    
                                if (random_word == answer) {
                                    //cheer.play();
                    
                                    // if you only need +1, you can use ++
                                    wordsCorrectCounter++;
                    
                                    document.getElementById("okBtn").remove();
                                    document.getElementById("inputfield").remove();
                    
                                    // use Array.filter() to remove random_word(answer) from the dictionary
                                    // only word != random_word will pass
                                    dictionary = dictionary.filter(item => item.word != random_word);
                                    console.log(dictionary);
                                    newWord();
                                } else {
                                    // I didn't see this, so I add it
                                    // if you only need +1, you can use ++
                                    wordsWrongCounter++;
                    
                                    // because we pass the random_word(answer) now, we can just push it
                                    wordsWrong.push(random_word);
                    
                                    document.getElementById("okBtn").remove();
                                    document.getElementById("inputfield").remove();
                                    //boo.play();
                                    document.body.style.backgroundColor = "red";
                                    document.getElementById("correctWord").innerHTML = random_word;
                                    
                                    let btn = document.createElement("button");
                                    btn.id = "contBtn";
                                    btn.innerHTML = "Continue";
                                    btn.type = "submit";
                                    btn.name = "continueBtn";
                                    document.body.appendChild(btn);
                    
                                    document.getElementById("contBtn").addEventListener("click", () => wrongAnswer(random_word));
                                }
                            }
                    
                            function wrongAnswer(random_word) {
                                document.getElementById("contBtn").remove();
                                document.getElementById("correctWord").innerHTML = "    ";
                                // same as above
                                // use Array.filter() to remove correct_word(answer) from the dictionary
                                // only word != correct_word will pass
                                dictionary = dictionary.filter(item => item.word != random_word);
                                newWord();
                            }
                    
                            function endGame() {
                                /*
                                use `` to set string, it more readable & easier to edit
                                you can put variable in it by use ${variable_name}
                    
                                example: 
                                let x = "test";
                                console.log(`this is a ${x}`);
                                
                                result:
                                this is a test
                                */
                                document.getElementById("Empty").innerHTML =
                                    `you are done! Correct: ${wordsCorrectCounter} Wrong: ${wordsWrongCounter} These words were wrong: ${wordsWrong}`;
                            }
                    
                            function Refresh() {
                                window.parent.location = window.parent.location.href;
                            }
                    
                            document.getElementById("startGame").addEventListener("click", () => startGame());
                        </script>
                    </body>
                    
                    </html>
                    dictionary = [
                        { word: "apple", audio: 'apple.mp3', },
                        { word: "baby", audio: 'baby.mp3', },
                        { word: "car", audio: 'car.mp3' }
                    ];
                    
                    dictionary = [
                        { word: "apple", audio: 'apple.mp3', },
                        { word: "baby", audio: 'baby.mp3', },
                    ];
                    
                    let dictionary = [
                        { word: "apple", audio: 'apple.mp3', },
                        { word: "baby", audio: 'baby.mp3', },
                        { word: "car", audio: 'car.mp3' }
                    ];
                    // only the item that item.word != "apple" will pass this
                    dictionary = dictionary.filter(item => item.word != "apple");
                    
                    console.log(dictionary);
                    let x = "test";
                    console.log(`this is a ${x}`);
                    let dictionary = [
                                { word: "apple", audio: 'apple.mp3', },
                                { word: "baby", audio: 'baby.mp3', },
                                { word: "car", audio: 'car.mp3' }
                            ],
                        target = dictionary.find(item => item.word=="apple"),
                        audio = false;
                    if(target) audio = target.audio;
                    console.log(audio);
                    <html>
                    
                    <head>
                        <title>Aliyah's dictee spel</title>
                        <link rel="stylesheet" type="text/css" href="style.css">
                    </head>
                    
                    <body>
                        <div id="header">
                            <h1>Hej! Velkommen til Aliyahs diktee!</h1>
                        </div>
                        <div id="Random_word">
                            <h2 id="Empty">Click start to start</h2>
                            <button id="startGame">Start</button>
                            <button id="editList">Edit word list</button>
                            <h3 id="correctWord"></h3>
                    
                        </div>
                        <script>
                            function sleep(ms) {
                                return new Promise(resolve => setTimeout(resolve, ms));
                            }
                    
                            var dictionary = [
                                { word: "apple", audio: 'apple.mp3', },
                                { word: "baby", audio: 'baby.mp3', },
                                { word: "car", audio: 'car.mp3' }
                            ];
                    
                            var wordsWrong = [];
                            var wordsCorrectCounter = 0;
                            var wordsWrongCounter = 0;
                            //var cheer = new Audio('correct.mp3');
                            //var boo = new Audio('wrong.mp3');
                    
                            function editWords() {
                                console.log("under construction");
                            }
                    
                            function startGame() {
                                document.getElementById("startGame").remove();
                                document.getElementById("editList").remove();
                                newWord();
                            }
                    
                            // dictionary is global variable, you don't need to pass it to access it
                            async function newWord() {
                    
                                // I add this so the color will be reset after click continue
                                document.body.style.backgroundColor = "";
                    
                                if (Object.entries(dictionary).length === 0) {
                                    endGame();
                                } else {
                                    var random = Math.floor(Math.random() * dictionary.length),
                                        // get the random word here when it still exist in dictionary
                                        random_word = dictionary[random].word;
                    
                                    document.getElementById("Empty").innerHTML = random_word;
                                    console.log(random_word);
                                    console.log(dictionary);
                                    await sleep(2000);
                                    document.getElementById("Empty").innerHTML = "       ";
                    
                                    // direct pass the ramdom word, not the ramdom index
                                    // ramdom index could be invalid after you remove item from dictionary
                                    // which is why you get the error
                                    createInputField(random_word);
                                }
                            }
                    
                            function createInputField(random_word) {
                                var entry = document.createElement("input");
                                entry.setAttribute("type", "text");
                                entry.id = "inputfield";
                                document.body.appendChild(entry);
                                let btn = document.createElement("button");
                                btn.id = "okBtn";
                                btn.innerHTML = "ok";
                                btn.type = "submit";
                                btn.name = "answerBtn";
                                document.body.appendChild(btn);
                                document.getElementById("okBtn").addEventListener("click", () => checkAnswer(random_word, entry.value));
                            }
                    
                            function checkAnswer(random_word, entry) {
                                var answer = entry.toLowerCase();
                    
                                if (random_word == answer) {
                                    //cheer.play();
                    
                                    // if you only need +1, you can use ++
                                    wordsCorrectCounter++;
                    
                                    document.getElementById("okBtn").remove();
                                    document.getElementById("inputfield").remove();
                    
                                    // use Array.filter() to remove random_word(answer) from the dictionary
                                    // only word != random_word will pass
                                    dictionary = dictionary.filter(item => item.word != random_word);
                                    console.log(dictionary);
                                    newWord();
                                } else {
                                    // I didn't see this, so I add it
                                    // if you only need +1, you can use ++
                                    wordsWrongCounter++;
                    
                                    // because we pass the random_word(answer) now, we can just push it
                                    wordsWrong.push(random_word);
                    
                                    document.getElementById("okBtn").remove();
                                    document.getElementById("inputfield").remove();
                                    //boo.play();
                                    document.body.style.backgroundColor = "red";
                                    document.getElementById("correctWord").innerHTML = random_word;
                                    
                                    let btn = document.createElement("button");
                                    btn.id = "contBtn";
                                    btn.innerHTML = "Continue";
                                    btn.type = "submit";
                                    btn.name = "continueBtn";
                                    document.body.appendChild(btn);
                    
                                    document.getElementById("contBtn").addEventListener("click", () => wrongAnswer(random_word));
                                }
                            }
                    
                            function wrongAnswer(random_word) {
                                document.getElementById("contBtn").remove();
                                document.getElementById("correctWord").innerHTML = "    ";
                                // same as above
                                // use Array.filter() to remove correct_word(answer) from the dictionary
                                // only word != correct_word will pass
                                dictionary = dictionary.filter(item => item.word != random_word);
                                newWord();
                            }
                    
                            function endGame() {
                                /*
                                use `` to set string, it more readable & easier to edit
                                you can put variable in it by use ${variable_name}
                    
                                example: 
                                let x = "test";
                                console.log(`this is a ${x}`);
                                
                                result:
                                this is a test
                                */
                                document.getElementById("Empty").innerHTML =
                                    `you are done! Correct: ${wordsCorrectCounter} Wrong: ${wordsWrongCounter} These words were wrong: ${wordsWrong}`;
                            }
                    
                            function Refresh() {
                                window.parent.location = window.parent.location.href;
                            }
                    
                            document.getElementById("startGame").addEventListener("click", () => startGame());
                        </script>
                    </body>
                    
                    </html>
                    dictionary = [
                        { word: "apple", audio: 'apple.mp3', },
                        { word: "baby", audio: 'baby.mp3', },
                        { word: "car", audio: 'car.mp3' }
                    ];
                    
                    dictionary = [
                        { word: "apple", audio: 'apple.mp3', },
                        { word: "baby", audio: 'baby.mp3', },
                    ];
                    
                    let dictionary = [
                        { word: "apple", audio: 'apple.mp3', },
                        { word: "baby", audio: 'baby.mp3', },
                        { word: "car", audio: 'car.mp3' }
                    ];
                    // only the item that item.word != "apple" will pass this
                    dictionary = dictionary.filter(item => item.word != "apple");
                    
                    console.log(dictionary);
                    let x = "test";
                    console.log(`this is a ${x}`);
                    let dictionary = [
                                { word: "apple", audio: 'apple.mp3', },
                                { word: "baby", audio: 'baby.mp3', },
                                { word: "car", audio: 'car.mp3' }
                            ],
                        target = dictionary.find(item => item.word=="apple"),
                        audio = false;
                    if(target) audio = target.audio;
                    console.log(audio);
                    <html>
                    
                    <head>
                        <title>Aliyah's dictee spel</title>
                        <link rel="stylesheet" type="text/css" href="style.css">
                    </head>
                    
                    <body>
                        <div id="header">
                            <h1>Hej! Velkommen til Aliyahs diktee!</h1>
                        </div>
                        <div id="Random_word">
                            <h2 id="Empty">Click start to start</h2>
                            <button id="startGame">Start</button>
                            <button id="editList">Edit word list</button>
                            <h3 id="correctWord"></h3>
                    
                        </div>
                        <script>
                            function sleep(ms) {
                                return new Promise(resolve => setTimeout(resolve, ms));
                            }
                    
                            var dictionary = [
                                { word: "apple", audio: 'apple.mp3', },
                                { word: "baby", audio: 'baby.mp3', },
                                { word: "car", audio: 'car.mp3' }
                            ];
                    
                            var wordsWrong = [];
                            var wordsCorrectCounter = 0;
                            var wordsWrongCounter = 0;
                            //var cheer = new Audio('correct.mp3');
                            //var boo = new Audio('wrong.mp3');
                    
                            function editWords() {
                                console.log("under construction");
                            }
                    
                            function startGame() {
                                document.getElementById("startGame").remove();
                                document.getElementById("editList").remove();
                                newWord();
                            }
                    
                            // dictionary is global variable, you don't need to pass it to access it
                            async function newWord() {
                    
                                // I add this so the color will be reset after click continue
                                document.body.style.backgroundColor = "";
                    
                                if (Object.entries(dictionary).length === 0) {
                                    endGame();
                                } else {
                                    var random = Math.floor(Math.random() * dictionary.length),
                                        // get the random word here when it still exist in dictionary
                                        random_word = dictionary[random].word;
                    
                                    document.getElementById("Empty").innerHTML = random_word;
                                    console.log(random_word);
                                    console.log(dictionary);
                                    await sleep(2000);
                                    document.getElementById("Empty").innerHTML = "       ";
                    
                                    // direct pass the ramdom word, not the ramdom index
                                    // ramdom index could be invalid after you remove item from dictionary
                                    // which is why you get the error
                                    createInputField(random_word);
                                }
                            }
                    
                            function createInputField(random_word) {
                                var entry = document.createElement("input");
                                entry.setAttribute("type", "text");
                                entry.id = "inputfield";
                                document.body.appendChild(entry);
                                let btn = document.createElement("button");
                                btn.id = "okBtn";
                                btn.innerHTML = "ok";
                                btn.type = "submit";
                                btn.name = "answerBtn";
                                document.body.appendChild(btn);
                                document.getElementById("okBtn").addEventListener("click", () => checkAnswer(random_word, entry.value));
                            }
                    
                            function checkAnswer(random_word, entry) {
                                var answer = entry.toLowerCase();
                    
                                if (random_word == answer) {
                                    //cheer.play();
                    
                                    // if you only need +1, you can use ++
                                    wordsCorrectCounter++;
                    
                                    document.getElementById("okBtn").remove();
                                    document.getElementById("inputfield").remove();
                    
                                    // use Array.filter() to remove random_word(answer) from the dictionary
                                    // only word != random_word will pass
                                    dictionary = dictionary.filter(item => item.word != random_word);
                                    console.log(dictionary);
                                    newWord();
                                } else {
                                    // I didn't see this, so I add it
                                    // if you only need +1, you can use ++
                                    wordsWrongCounter++;
                    
                                    // because we pass the random_word(answer) now, we can just push it
                                    wordsWrong.push(random_word);
                    
                                    document.getElementById("okBtn").remove();
                                    document.getElementById("inputfield").remove();
                                    //boo.play();
                                    document.body.style.backgroundColor = "red";
                                    document.getElementById("correctWord").innerHTML = random_word;
                                    
                                    let btn = document.createElement("button");
                                    btn.id = "contBtn";
                                    btn.innerHTML = "Continue";
                                    btn.type = "submit";
                                    btn.name = "continueBtn";
                                    document.body.appendChild(btn);
                    
                                    document.getElementById("contBtn").addEventListener("click", () => wrongAnswer(random_word));
                                }
                            }
                    
                            function wrongAnswer(random_word) {
                                document.getElementById("contBtn").remove();
                                document.getElementById("correctWord").innerHTML = "    ";
                                // same as above
                                // use Array.filter() to remove correct_word(answer) from the dictionary
                                // only word != correct_word will pass
                                dictionary = dictionary.filter(item => item.word != random_word);
                                newWord();
                            }
                    
                            function endGame() {
                                /*
                                use `` to set string, it more readable & easier to edit
                                you can put variable in it by use ${variable_name}
                    
                                example: 
                                let x = "test";
                                console.log(`this is a ${x}`);
                                
                                result:
                                this is a test
                                */
                                document.getElementById("Empty").innerHTML =
                                    `you are done! Correct: ${wordsCorrectCounter} Wrong: ${wordsWrongCounter} These words were wrong: ${wordsWrong}`;
                            }
                    
                            function Refresh() {
                                window.parent.location = window.parent.location.href;
                            }
                    
                            document.getElementById("startGame").addEventListener("click", () => startGame());
                        </script>
                    </body>
                    
                    </html>
                    dictionary = [
                        { word: "apple", audio: 'apple.mp3', },
                        { word: "baby", audio: 'baby.mp3', },
                        { word: "car", audio: 'car.mp3' }
                    ];
                    
                    dictionary = [
                        { word: "apple", audio: 'apple.mp3', },
                        { word: "baby", audio: 'baby.mp3', },
                    ];
                    
                    let dictionary = [
                        { word: "apple", audio: 'apple.mp3', },
                        { word: "baby", audio: 'baby.mp3', },
                        { word: "car", audio: 'car.mp3' }
                    ];
                    // only the item that item.word != "apple" will pass this
                    dictionary = dictionary.filter(item => item.word != "apple");
                    
                    console.log(dictionary);
                    let x = "test";
                    console.log(`this is a ${x}`);
                    let dictionary = [
                                { word: "apple", audio: 'apple.mp3', },
                                { word: "baby", audio: 'baby.mp3', },
                                { word: "car", audio: 'car.mp3' }
                            ],
                        target = dictionary.find(item => item.word=="apple"),
                        audio = false;
                    if(target) audio = target.audio;
                    console.log(audio);
                    <html>
                    
                    <head>
                        <title>Aliyah's dictee spel</title>
                        <link rel="stylesheet" type="text/css" href="style.css">
                    </head>
                    
                    <body>
                        <div id="header">
                            <h1>Hej! Velkommen til Aliyahs diktee!</h1>
                        </div>
                        <div id="Random_word">
                            <h2 id="Empty">Click start to start</h2>
                            <button id="startGame">Start</button>
                            <button id="editList">Edit word list</button>
                            <h3 id="correctWord"></h3>
                    
                        </div>
                        <script>
                            function sleep(ms) {
                                return new Promise(resolve => setTimeout(resolve, ms));
                            }
                    
                            var dictionary = [
                                { word: "apple", audio: 'apple.mp3', },
                                { word: "baby", audio: 'baby.mp3', },
                                { word: "car", audio: 'car.mp3' }
                            ];
                    
                            var wordsWrong = [];
                            var wordsCorrectCounter = 0;
                            var wordsWrongCounter = 0;
                            //var cheer = new Audio('correct.mp3');
                            //var boo = new Audio('wrong.mp3');
                    
                            function editWords() {
                                console.log("under construction");
                            }
                    
                            function startGame() {
                                document.getElementById("startGame").remove();
                                document.getElementById("editList").remove();
                                newWord();
                            }
                    
                            // dictionary is global variable, you don't need to pass it to access it
                            async function newWord() {
                    
                                // I add this so the color will be reset after click continue
                                document.body.style.backgroundColor = "";
                    
                                if (Object.entries(dictionary).length === 0) {
                                    endGame();
                                } else {
                                    var random = Math.floor(Math.random() * dictionary.length),
                                        // get the random word here when it still exist in dictionary
                                        random_word = dictionary[random].word;
                    
                                    document.getElementById("Empty").innerHTML = random_word;
                                    console.log(random_word);
                                    console.log(dictionary);
                                    await sleep(2000);
                                    document.getElementById("Empty").innerHTML = "       ";
                    
                                    // direct pass the ramdom word, not the ramdom index
                                    // ramdom index could be invalid after you remove item from dictionary
                                    // which is why you get the error
                                    createInputField(random_word);
                                }
                            }
                    
                            function createInputField(random_word) {
                                var entry = document.createElement("input");
                                entry.setAttribute("type", "text");
                                entry.id = "inputfield";
                                document.body.appendChild(entry);
                                let btn = document.createElement("button");
                                btn.id = "okBtn";
                                btn.innerHTML = "ok";
                                btn.type = "submit";
                                btn.name = "answerBtn";
                                document.body.appendChild(btn);
                                document.getElementById("okBtn").addEventListener("click", () => checkAnswer(random_word, entry.value));
                            }
                    
                            function checkAnswer(random_word, entry) {
                                var answer = entry.toLowerCase();
                    
                                if (random_word == answer) {
                                    //cheer.play();
                    
                                    // if you only need +1, you can use ++
                                    wordsCorrectCounter++;
                    
                                    document.getElementById("okBtn").remove();
                                    document.getElementById("inputfield").remove();
                    
                                    // use Array.filter() to remove random_word(answer) from the dictionary
                                    // only word != random_word will pass
                                    dictionary = dictionary.filter(item => item.word != random_word);
                                    console.log(dictionary);
                                    newWord();
                                } else {
                                    // I didn't see this, so I add it
                                    // if you only need +1, you can use ++
                                    wordsWrongCounter++;
                    
                                    // because we pass the random_word(answer) now, we can just push it
                                    wordsWrong.push(random_word);
                    
                                    document.getElementById("okBtn").remove();
                                    document.getElementById("inputfield").remove();
                                    //boo.play();
                                    document.body.style.backgroundColor = "red";
                                    document.getElementById("correctWord").innerHTML = random_word;
                                    
                                    let btn = document.createElement("button");
                                    btn.id = "contBtn";
                                    btn.innerHTML = "Continue";
                                    btn.type = "submit";
                                    btn.name = "continueBtn";
                                    document.body.appendChild(btn);
                    
                                    document.getElementById("contBtn").addEventListener("click", () => wrongAnswer(random_word));
                                }
                            }
                    
                            function wrongAnswer(random_word) {
                                document.getElementById("contBtn").remove();
                                document.getElementById("correctWord").innerHTML = "    ";
                                // same as above
                                // use Array.filter() to remove correct_word(answer) from the dictionary
                                // only word != correct_word will pass
                                dictionary = dictionary.filter(item => item.word != random_word);
                                newWord();
                            }
                    
                            function endGame() {
                                /*
                                use `` to set string, it more readable & easier to edit
                                you can put variable in it by use ${variable_name}
                    
                                example: 
                                let x = "test";
                                console.log(`this is a ${x}`);
                                
                                result:
                                this is a test
                                */
                                document.getElementById("Empty").innerHTML =
                                    `you are done! Correct: ${wordsCorrectCounter} Wrong: ${wordsWrongCounter} These words were wrong: ${wordsWrong}`;
                            }
                    
                            function Refresh() {
                                window.parent.location = window.parent.location.href;
                            }
                    
                            document.getElementById("startGame").addEventListener("click", () => startGame());
                        </script>
                    </body>
                    
                    </html>
                    dictionary = [
                        { word: "apple", audio: 'apple.mp3', },
                        { word: "baby", audio: 'baby.mp3', },
                        { word: "car", audio: 'car.mp3' }
                    ];
                    
                    dictionary = [
                        { word: "apple", audio: 'apple.mp3', },
                        { word: "baby", audio: 'baby.mp3', },
                    ];
                    
                    let dictionary = [
                        { word: "apple", audio: 'apple.mp3', },
                        { word: "baby", audio: 'baby.mp3', },
                        { word: "car", audio: 'car.mp3' }
                    ];
                    // only the item that item.word != "apple" will pass this
                    dictionary = dictionary.filter(item => item.word != "apple");
                    
                    console.log(dictionary);
                    let x = "test";
                    console.log(`this is a ${x}`);
                    let dictionary = [
                                { word: "apple", audio: 'apple.mp3', },
                                { word: "baby", audio: 'baby.mp3', },
                                { word: "car", audio: 'car.mp3' }
                            ],
                        target = dictionary.find(item => item.word=="apple"),
                        audio = false;
                    if(target) audio = target.audio;
                    console.log(audio);
                    <html>
                    
                    <head>
                        <title>Aliyah's dictee spel</title>
                        <link rel="stylesheet" type="text/css" href="style.css">
                    </head>
                    
                    <body>
                        <div id="header">
                            <h1>Hej! Velkommen til Aliyahs diktee!</h1>
                        </div>
                        <div id="Random_word">
                            <h2 id="Empty">Click start to start</h2>
                            <button id="startGame">Start</button>
                            <button id="editList">Edit word list</button>
                            <h3 id="correctWord"></h3>
                    
                        </div>
                        <script>
                            function sleep(ms) {
                                return new Promise(resolve => setTimeout(resolve, ms));
                            }
                    
                            var dictionary = [
                                { word: "apple", audio: 'apple.mp3', },
                                { word: "baby", audio: 'baby.mp3', },
                                { word: "car", audio: 'car.mp3' }
                            ];
                    
                            var wordsWrong = [];
                            var wordsCorrectCounter = 0;
                            var wordsWrongCounter = 0;
                            //var cheer = new Audio('correct.mp3');
                            //var boo = new Audio('wrong.mp3');
                    
                            function editWords() {
                                console.log("under construction");
                            }
                    
                            function startGame() {
                                document.getElementById("startGame").remove();
                                document.getElementById("editList").remove();
                                newWord();
                            }
                    
                            // dictionary is global variable, you don't need to pass it to access it
                            async function newWord() {
                    
                                // I add this so the color will be reset after click continue
                                document.body.style.backgroundColor = "";
                    
                                if (Object.entries(dictionary).length === 0) {
                                    endGame();
                                } else {
                                    var random = Math.floor(Math.random() * dictionary.length),
                                        // get the random word here when it still exist in dictionary
                                        random_word = dictionary[random].word;
                    
                                    document.getElementById("Empty").innerHTML = random_word;
                                    console.log(random_word);
                                    console.log(dictionary);
                                    await sleep(2000);
                                    document.getElementById("Empty").innerHTML = "       ";
                    
                                    // direct pass the ramdom word, not the ramdom index
                                    // ramdom index could be invalid after you remove item from dictionary
                                    // which is why you get the error
                                    createInputField(random_word);
                                }
                            }
                    
                            function createInputField(random_word) {
                                var entry = document.createElement("input");
                                entry.setAttribute("type", "text");
                                entry.id = "inputfield";
                                document.body.appendChild(entry);
                                let btn = document.createElement("button");
                                btn.id = "okBtn";
                                btn.innerHTML = "ok";
                                btn.type = "submit";
                                btn.name = "answerBtn";
                                document.body.appendChild(btn);
                                document.getElementById("okBtn").addEventListener("click", () => checkAnswer(random_word, entry.value));
                            }
                    
                            function checkAnswer(random_word, entry) {
                                var answer = entry.toLowerCase();
                    
                                if (random_word == answer) {
                                    //cheer.play();
                    
                                    // if you only need +1, you can use ++
                                    wordsCorrectCounter++;
                    
                                    document.getElementById("okBtn").remove();
                                    document.getElementById("inputfield").remove();
                    
                                    // use Array.filter() to remove random_word(answer) from the dictionary
                                    // only word != random_word will pass
                                    dictionary = dictionary.filter(item => item.word != random_word);
                                    console.log(dictionary);
                                    newWord();
                                } else {
                                    // I didn't see this, so I add it
                                    // if you only need +1, you can use ++
                                    wordsWrongCounter++;
                    
                                    // because we pass the random_word(answer) now, we can just push it
                                    wordsWrong.push(random_word);
                    
                                    document.getElementById("okBtn").remove();
                                    document.getElementById("inputfield").remove();
                                    //boo.play();
                                    document.body.style.backgroundColor = "red";
                                    document.getElementById("correctWord").innerHTML = random_word;
                                    
                                    let btn = document.createElement("button");
                                    btn.id = "contBtn";
                                    btn.innerHTML = "Continue";
                                    btn.type = "submit";
                                    btn.name = "continueBtn";
                                    document.body.appendChild(btn);
                    
                                    document.getElementById("contBtn").addEventListener("click", () => wrongAnswer(random_word));
                                }
                            }
                    
                            function wrongAnswer(random_word) {
                                document.getElementById("contBtn").remove();
                                document.getElementById("correctWord").innerHTML = "    ";
                                // same as above
                                // use Array.filter() to remove correct_word(answer) from the dictionary
                                // only word != correct_word will pass
                                dictionary = dictionary.filter(item => item.word != random_word);
                                newWord();
                            }
                    
                            function endGame() {
                                /*
                                use `` to set string, it more readable & easier to edit
                                you can put variable in it by use ${variable_name}
                    
                                example: 
                                let x = "test";
                                console.log(`this is a ${x}`);
                                
                                result:
                                this is a test
                                */
                                document.getElementById("Empty").innerHTML =
                                    `you are done! Correct: ${wordsCorrectCounter} Wrong: ${wordsWrongCounter} These words were wrong: ${wordsWrong}`;
                            }
                    
                            function Refresh() {
                                window.parent.location = window.parent.location.href;
                            }
                    
                            document.getElementById("startGame").addEventListener("click", () => startGame());
                        </script>
                    </body>
                    
                    </html>

                    private member data not being available to public member function

                    copy iconCopydownload iconDownload
                    int my_n_rows = gameBoard.numRows(); //Import number of rows
                    int my_n_cols = gameBoard.numCols(); //Import number of cols
                    
                    my_n_rows = gameBoard.numRows(); //Import number of rows
                    my_n_cols = gameBoard.numCols(); //Import number of cols
                    
                    void ResetTrackingTable(int rows, int cols); 
                    
                    void WordGame::ResetTrackingTable() { // ...
                    
                    int my_n_rows = gameBoard.numRows(); //Import number of rows
                    int my_n_cols = gameBoard.numCols(); //Import number of cols
                    
                    my_n_rows = gameBoard.numRows(); //Import number of rows
                    my_n_cols = gameBoard.numCols(); //Import number of cols
                    
                    void ResetTrackingTable(int rows, int cols); 
                    
                    void WordGame::ResetTrackingTable() { // ...
                    
                    int my_n_rows = gameBoard.numRows(); //Import number of rows
                    int my_n_cols = gameBoard.numCols(); //Import number of cols
                    
                    my_n_rows = gameBoard.numRows(); //Import number of rows
                    my_n_cols = gameBoard.numCols(); //Import number of cols
                    
                    void ResetTrackingTable(int rows, int cols); 
                    
                    void WordGame::ResetTrackingTable() { // ...
                    
                    int my_n_rows = gameBoard.numRows(); //Import number of rows
                    int my_n_cols = gameBoard.numCols(); //Import number of cols
                    
                    my_n_rows = gameBoard.numRows(); //Import number of rows
                    my_n_cols = gameBoard.numCols(); //Import number of cols
                    
                    void ResetTrackingTable(int rows, int cols); 
                    
                    void WordGame::ResetTrackingTable() { // ...
                    

                    Community Discussions

                    Trending Discussions on wordgame
                    • React useState not updating
                    • Print random line from text file in java
                    • Random value not in the range of array/dictionary
                    • private member data not being available to public member function
                    Trending Discussions on wordgame

                    QUESTION

                    React useState not updating

                    Asked 2022-Feb-23 at 01:12

                    I'm learning React and I know this subject has been covered by many questions, but they all are focused on the asynchronous nature of useState. I'm not sure if that's what's happening here. I also tried a version in combination with useEffect, and the result was the same.

                    I have a component where I'm listening to keypresses - user is trying to guess a word. Once the word is guessed, the word object is supposed to be replaced with another one and a new puzzle begins.

                    The component renders using the correct state (characters of the new word), but when trying the first guess of the second puzzle, the word object is still the original state object.

                    How can I update this word object correctly?

                    CodeSandbox

                    Steps to reproduce in the readme.md:

                    const WordFrame = () => {
                        const [word, setWord] = useState(() => new Word 'apple');
                        const [renderedCharacters, setRenderedCharacters] = useState(
                            word.renderedCharacters
                        );
                    
                        const keyDownHandler = (e: KeyboardEvent): void => {
                            console.log(e.key);
                            if (letters.includes(e.key)) {
                                const correctGuess = word.processGuess(e.key);
                    
                                if (correctGuess) {
                                    setRenderedCharacters([...word.renderedCharacters]);
                                    
                                    // moving the following if block into useEffect with dependency on word.isGuessed and renderedCharacters doesn't help
                                    if (word.isGuessed) {
                                        const newWord: Word = new Word('banana');
                                        setWord(newWord);
                                        setRenderedCharacters(newWord.renderedCharacters);
                                    }
                                }
                            }
                        };
                    
                        useEffect(() => {
                            document.addEventListener('keydown', keyDownHandler);
                            return () => document.removeEventListener('keydown', keyDownHandler);
                        }, []);
                    
                        // useEffect(() => {
                            // if (word.isGuessed) {
                            //     const newWord = new Word('banana);
                            //     setWord(newWord);
                            //     setRenderedCharacters(newWord.renderedCharacters);
                            // }
                        // }, [word.isGuessed, renderedCharacters]);
                    
                        return (
                            <div className='word-frame'>
                                {renderedCharacters.map((c) => (
                                    <LetterFrame characterValue={c.value} key={c.id} />
                                ))}
                            </div>
                        );
                    };
                    
                    export default WordFrame;
                    
                    

                    Word.ts

                    class Word {
                        private readonly _unguessedCharacter: string = ' ';
                        private readonly _characters: string[] = [];
                        private _guessingIndex = 0;
                    
                        private _renderedCharacters: Character[] = [];
                        public get renderedCharacters() {
                            return this._renderedCharacters;
                        }
                    
                        private _isGuessed: boolean = false;
                        public get isGuessed(): boolean {
                            return this._isGuessed;
                        }
                    
                        constructor(wordString: string) {
                            console.log(`Word.constructor called with parameter: ${wordString}`);
                            this._characters = wordString.split('');
                            this.setRenderedCharacters();
                        }
                    
                        public processGuess(letter: string): boolean {
                            const isSuccessfulGuess = (): boolean =>
                                this._characters[this._guessingIndex].toLowerCase() ===
                                letter.toLowerCase();
                    
                            const successful = isSuccessfulGuess();
                    
                            if (successful) {
                                this._guessingIndex++;
                                this.setRenderedCharacters();
                            }
                    
                            if (this._guessingIndex > this._characters.length - 1) {
                                this._isGuessed = true;
                            }
                    
                            return successful;
                        }
                    
                        private setRenderedCharacters(): void {
                            this._renderedCharacters = [];
                    
                            this._characters.forEach((c, i): void => {
                                if (i >= this._guessingIndex) {
                                    this._renderedCharacters.push(
                                        new Character(this._unguessedCharacter)
                                    );
                                } else {
                                    this._renderedCharacters.push(new Character(c));
                                }
                            });
                        }
                    }
                    
                    export default Word;
                    

                    ANSWER

                    Answered 2022-Feb-21 at 09:04

                    It's hard to debug without a codesandbox but I'm guessing since you want the useEffect to trigger when you do

                    setRenderedCharacters([...word.renderedCharacters]);

                    You should add renderedCharacters as the dependency

                    useEffect(() => {
                             if (word.isGuessed) {
                                 const newWord = getWord();
                                 setWord(newWord);
                                 setRenderedCharacters(newWord.renderedCharacters);
                             }
                    }, [word.isGuessed, renderedCharacters]);
                    
                    

                    Source https://stackoverflow.com/questions/71199750

                    Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                    Vulnerabilities

                    No vulnerabilities reported

                    Install wordgame

                    You can download it from GitHub.
                    You can use wordgame like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the wordgame component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

                    Support

                    For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

                    DOWNLOAD this Library from

                    Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                    over 430 million Knowledge Items
                    Find more libraries
                    Reuse Solution Kits and Libraries Curated by Popular Use Cases
                    Explore Kits

                    Save this library and start creating your kit

                    Share this Page

                    share link
                    Consider Popular Java Libraries
                    Try Top Libraries by shekhargulati
                    Compare Java Libraries with Highest Support
                    Compare Java Libraries with Highest Quality
                    Compare Java Libraries with Highest Security
                    Compare Java Libraries with Permissive License
                    Compare Java Libraries with Highest Reuse
                    Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                    over 430 million Knowledge Items
                    Find more libraries
                    Reuse Solution Kits and Libraries Curated by Popular Use Cases
                    Explore Kits

                    Save this library and start creating your kit

                    • © 2022 Open Weaver Inc.