lundi 13 juillet 2020

How do I redirect the page if the word is correct

        <FORM NAME="WordForm">  
            <INPUT TYPE=TEXT NAME="WordBox" id="wordbox"><BR>
            <INPUT  id="button" TYPE=BUTTON VALUE="Generate" onClick="PickRandomWord(document.WordForm);">
                
                <script>
                var NumberOfWords = 3
            
            var words = new BuildArray(NumberOfWords)
            
            // Use the following variables to 
            // define your random words:
            words[1] = "M _ T _"
            words[2] = "F _ _ T _ _ L _"
            words[3] = "K _ Y _ _ A _ _"
            
            function BuildArray(size){
            this.length = size
            for (var i = 1; i <= size; i++){
            this[i] = null}
            return this
            }
            
            function PickRandomWord(frm) {
                button.style.visibility = "hidden";
            var rnd = Math.ceil(Math.random() * NumberOfWords)
            
            frm.WordBox.value = words[rnd]
            }
            </script>
    <div>
      <label for="name" style="color:purple; background-color:rgb(223, 247, 10)" style="font-family:verdana">K _ Y _ _ A _ _</label>

      <input type="text" name="Enter_the_word" id="Enter_the_word" placeholder="Enter_the_word" required><br>


      <br>



      <button type="submit" style="background-color: blue; color: yellow" onclick="myFunction()">NEXT LEVEL</button>

    </div>

    <p id="demo"></p>
    <button onclick="typeWriter()">Click me to get a quick hint😃</button>

    <p id="demo"></p>
    <script>
      function myFunction() {
        if (document.getElementById("Enter_the_word").value != "KEYBOARD") {
            location.href = 'index.html';
        } else if (document.getElementById("Enter_the_word").value == "KEYBOARD") {
          location.href = "index4.html";
        }

      }
    </script>

I am making this word guessing game - I want to make the page redirect to the next level of the game if the answer is correct but if the answer is wrong I want it to go back to the home page that is index.html So if the answer is right than to "index 4.html" or if the answer is wrong then to "index.html" The anser can be three different words that are - KEYBOARD,FOOTBALL and MATH The answer can be one word which will be generated by the generator. Thank you




Aucun commentaire:

Enregistrer un commentaire