0

I am trying to put my innerHTML text inside of my paragraph element I created but its not working. I don't understand what I'm doing wrong. Can someone please tell me how I can fix this?

<!DOCTYPE html>
<html>
    <head>
        <title>
            JavaScript Tutorials
        </title>
        <style>
            #output {
                width: 120px;
                height: 20px;
                background-color: #CCC;
                border: 1px solid #666;
            }
        </style>
        <script>
            var apples = 25;
            var oranges = 30;

            if (apples < oranges) {
                document.getElementById("output").innerHTML = "Whats up guys";
            }
        </script>
    </head>

    <body>
        <p id="output"></p>
    </body>
</html>
talemyn
  • 7,822
  • 4
  • 31
  • 52
TechCheck
  • 1
  • 1
  • 1
    Because the error message in your developer console will tell you exactly the issue. – epascarello Apr 19 '17 at 19:19
  • 2
    Your JS is executing before the DOM has rendered. Move your JS to the bottom of the `body`. –  Apr 19 '17 at 19:19
  • Try wrapping your JS code into a function and then call that function on the `onLoad` event. – mfirry Apr 19 '17 at 19:20

0 Answers0