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) => {
key.addEventListener('click', () => {
if (output.textContent.length >= 1) {
output.innerHTML = '';
}
for (let i = 0; i < 8; i++) {
let select = Math.round(Math.random() * 6);
let note = scale[select];
output.innerHTML += note + ', ';
}
});
});
}
pattern(regCscale);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
<h1 class="title">Melody Help</h1>
<div class="reg-scales">
<div class="c-scale regKey">C</div>
<div class="c#-scale regKey">C#</div>
<div class="d-scale regKey">D</div>
<div class="d#-scale regKey">D#</div>
<div class="e-scale regKey">E</div>
<div class="f-scale regKey">F</div>
<div class="f#-scale regKey">F#</div>
<div class="g-scale regKey">G</div>
<div class="g#-scale regKey">G#</div>
<div class="a-scale regKey">A</div>
<div class="a#-scale regKey">A#</div>
<div class="b-scale regKey">B</div>
</div>
<div class="output"></div>
<script src="index.js"></script>
</body>
</html>
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.