title: Random Background Images
body: <p>I wanted to have a random background image each time a page loads, from a list of 5 images.</p>
  <p>I was trying to follow this questions,</p>
  <p><a href="https://stackoverflow.com/questions/15231812/random-background-images-css3?noredirect=1&amp;lq=1">Random background images CSS3</a></p>
  <p>but it never gets officially answered, and I can't quite make it work. It feels like it should work though, and I might be missing something simple.</p>
  <p>I want to put this in the _Layout page, so it applies to each page. It's kind of TMI, but I'm in VS2019, asp core mvc in c#.</p>
  <p>This is what I got:</p>
  <pre><code>&lt;head&gt;
  &lt;style&gt;...&lt;/style&gt;
  &lt;script type=&quot;text/javascript&quot;&gt;
          var totalCount = 8;
          function ChangeIt() {
              var num = Math.ceil(Math.random() * totalCount);
              document.body.background = 'assets/bgImages/' + num + '.jpg';
              document.body.style.backgroundRepeat = &quot;repeat&quot;;    // Background repeat
          }
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;...&lt;/body&gt;
  
  &lt;/html&gt;
  &lt;script type=&quot;text/javascript&quot;&gt;
      ChangeIt();
  &lt;/script&gt;
  </code></pre>