My javascript is running in the console, but returns an error if I run it through html : <p>I have some javascript code here, that randomly changes the background of the landing page of my website. This is the code:</p>

<pre><code>    var bigSize = [ 
                    "url('assets/bg/front1.jpg')",
                    "url('assets/bg/front2.jpg')",
                  ];
    var random = Math.floor(Math.random() * 2) + 0;
    document.getElementById("front").style.backgroundImage=bigSize[random];
</code></pre>

<p>When I load the page and take a look at my console, it gives the following error:</p>

<pre><code>background.js:6 Uncaught TypeError: Cannot read property 'style' of null
    at background.js:6
</code></pre>

<p>However, when I run the exact code through the console, the script works perfectly. Can anyone help me with this? Thanks in advance!</p>
