I have an array and the idea behind is to take these value from said array and add them to HTML buttons which would serve as questions for a quiz. I got the code to take the values from the array randomly, but the issue I have is that I sometimes get two buttons with the same value added, instead of each button being a unique entry from the array. The array itself doesn't contain duplicates.
const genres = ["Crime", "Action", "Drama", "Thriller", "Horror", "Comedy", "History", "Romance", "Adventure", "Epic", "Sci-Fi"];
let answers = document.querySelectorAll('.answer');
[].forEach.call(answers, function(answers) {
randGenres = Math.floor(Math.random() * genres.length);
answers.innerHTML = genres[randGenres];
});
<div class="container">
<h5 class="modal-title">Modal title</h5>
<div class="question">
</div>
<button class="answer">Some Answer</button>
<button class="answer">Some Answer</button>
<button class="answer">Some Answer</button>
<button class="answer">Some Answer</button>
</div>