[Solved] Uncaught TypeError: document.getElementById(...).innerHTML is not a function

Discussion in 'Programming' started by JacobRocks12, Nov 2, 2015.

  1. I know this is being posted every where but they usually just say it is a typing error but I have been researching everywhere. I get this error but I am doing everything correct! Code:
    HTML:
    <HTML>
        <head>
            <title>
                Number Guessing Game
            </title>
        </head>
       
        <script>
            function generateNumber() {
                var randomnumber = Math.round( Math.random() * (32000 - 1) + 1 );
                checkNumber(randomnumber);
            };
           
            function checkNumber(randomnumber) {
                var value = document.getElementById("input").innerHTML();
                if (value == randomnumber) {
                    document.getElementById("header").innerHTML = "You won! Refresh to play again."
                } else if (value > randomnumber) {
                    document.getElementById("header").innerHTML = "Less"
                } else if (value < randomnumber) {
                   document.getElementById("header").innerHTML = "More"
               }
           }
       </script>
       
        <body onload="generateNumber()">
            <center>
                <br><br><br>
                <h2 id="header">Enter a Number; Ranges 1 to 32000.</h2><br>
                <input type="number" id="input" placeholder="Number" /><br><br>
                <input type="button" onclick="checkNumber();" value="Check"></input>
        </body>
    </HTML>
     
  2. innerHTML is not a function, yet you're using it as if it were one on the first line in your checkNumber function. Remove the trailing parentheses.
     
    • Agree Agree x 1

Share This Page