title: Javascript.js:6 Uncaught TypeError: Cannot set property 'background' of undefined
body: <p>I need to assign each of the divs a color in the array colors, using a for in</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 colors = ["#232323","#343434","#555555","#989889","#987898","#458676"]
  
  var squares=document.querySelectorAll(".square")
  
  for (i=0; i&lt;squares.length; i++){
    squares[i].style.background=colors[i]
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>body {
    background: black;
  }
  
  .square {
    float : left;
    height: 30%;
    width:30%;
    background-color: red;
    margin : 1%;
  }
  
  .container {
    max-width: 600p1%</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;iDOCTYPE&gt;
  &lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Proyecto Color Game&lt;/title&gt;
    &lt;link rel="stylesheet" href="bootstrap-3.3.7-dist/css/bootstrap.css"&gt;
    &lt;link rel="stylesheet" href="stylesheet.css"&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div class="container" align="center"&gt;
  
        &lt;div class="square"&gt;&lt;/div&gt;
        &lt;div class="square"&gt;&lt;/div&gt;
        &lt;div class="square"&gt;&lt;/div&gt;
        &lt;div class="square"&gt;&lt;/div&gt;
        &lt;div class="square"&gt;&lt;/div&gt;
        &lt;div class="square"&gt;&lt;/div&gt;
  &lt;/div&gt;
  
  
  &lt;script src="Javascript.js" &gt;&lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>