title: How to Pass An Array Through a Function Parameter - javascript
body: <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>const regKeys = document.querySelectorAll('.regKey');
  const regCscale = ['c', 'd', 'e', 'f', 'g', 'a', 'b'];
  const output = document.querySelector('.output');
  
  function pattern(scale) {
      scale.forEach((key) =&gt; {
          key.addEventListener('click', () =&gt; {
              if (output.textContent.length &gt;= 1) {
                  output.innerHTML = '';
              }
              for (let i = 0; i &lt; 8; i++) {
                  let select = Math.round(Math.random() * 6);
                  let note = scale[select];
                  output.innerHTML += note + ', ';
              }
          });
      });
  }
  
  pattern(regCscale);</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;Title&lt;/title&gt;
      &lt;link rel="stylesheet" href="index.css"&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;h1 class="title"&gt;Melody Help&lt;/h1&gt;
  
  &lt;div class="reg-scales"&gt;
      &lt;div class="c-scale regKey"&gt;C&lt;/div&gt;
      &lt;div class="c#-scale regKey"&gt;C#&lt;/div&gt;
      &lt;div class="d-scale regKey"&gt;D&lt;/div&gt;
      &lt;div class="d#-scale regKey"&gt;D#&lt;/div&gt;
      &lt;div class="e-scale regKey"&gt;E&lt;/div&gt;
      &lt;div class="f-scale regKey"&gt;F&lt;/div&gt;
      &lt;div class="f#-scale regKey"&gt;F#&lt;/div&gt;
      &lt;div class="g-scale regKey"&gt;G&lt;/div&gt;
      &lt;div class="g#-scale regKey"&gt;G#&lt;/div&gt;
      &lt;div class="a-scale regKey"&gt;A&lt;/div&gt;
      &lt;div class="a#-scale regKey"&gt;A#&lt;/div&gt;
      &lt;div class="b-scale regKey"&gt;B&lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div class="output"&gt;&lt;/div&gt;
  
  &lt;script src="index.js"&gt;&lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>I've tried to find help similar to my situation but I can't find one. Im making a program that generates different notes of the piano based on scales and I can't pass the array of the different scales into my function.</p>