title: Copying background color using variables in JavaScript
body: <p>I want to be able to copy a clicked box's color and store it as the variable <code>newColor</code>.</p>
  <p>My function <code>selectColor(color)</code>, which is passed the property of <code>background-color</code>, gives me the error <em>&quot;Uncaught ReferenceError: color is not defined&quot;.</em> Do I need to define the variable that I use in as a parameter of a function separately, for example when I define <code>var newColor</code>?</p>
  <p>Full code: <a href="https://codepen.io/Lukedoc321/pen/GRENxao" rel="nofollow noreferrer">https://codepen.io/Lukedoc321/pen/GRENxao</a></p>
  <pre><code>&lt;p id=&quot;redSelector&quot; style=&quot;background-color:red;&quot; onclick=&quot;selectColor(event.target.style.background-color)&quot;&gt;Copy me!&lt;/p&gt;
  </code></pre>
  <pre><code>var newColor = &quot;purple&quot;; 
  
  function selectColor(color) { //Selects/saves the new color
    newColor = color; //Updates variable with color of the clicked cell
  }
  </code></pre>