title: Spawn blocks at random locations
body: <p>I'm trying to create elements in random locations on the screen but I have run into some trouble. Creating the elements works but when I try to make them have random locations, nothing happens. Thanks for the help in advance.</p>
  
  <p>Here's my code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var newObject = document.createElement("DIV");
  newObject.setAttribute("class", "object");
  newObject.setAttribute("id", "powerup");
  document.body.appendChild(newObject);
  var powerup = document.getElementById("powerup");
  var object = document.getElementsByClassName("object");
  for (i = 0; i &lt; object.length; i++) {
    object[i].style.top = Math.floor(Math.random() * window.innerHeight) + 50 + "px";
    object[i].style.left = Math.floor(Math.random() * window.innerWidth) + 50 + "px";
  }
  
  function createObject() {
    var newObject = document.createElement("DIV");
    newObject.setAttribute("class", "object");
    newObject.setAttribute("id", "powerup");
    document.body.appendChild(newObject);
    for (i = 0; i &lt; object.length; i++) {
      object[i].style.top = Math.floor(Math.random() * window.innerHeight) + 50 + "px";
      object[i].style.left = Math.floor(Math.random() * window.innerWidth) + 50 + "px";
    }
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>html, body {
    height: 100%;
    width: 100%;
    margin: 0;
  }
  #powerup {
    background: red;
    height: 10px;
    width: 10px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;body&gt;
    &lt;button onclick="createObject()"&gt;Create a Block&lt;/button&gt;
  &lt;/body&gt;</code></pre>
  </div>
  </div>
  </p>