I'm trying to alternate between players and give each one a question, now the players names are stored in an array, I'm trying random, but it's not working.
var counter = 0;
const limit = 4 * localStorage.getItem('playersNum');
nextBtn.addEventListener('click', function() {
if(counter < limit) {
// Display player's name and ask question
for (let i = 0; i < names.length; i++) {
randomName = names[Math.floor(Math.random()*names.length)];
const playerName = document.getElementById('card-title');
playerName.innerText = randomName;
}
const h6 = document.getElementById('h6');
h6.innerHTML = "Question " + (counter + 1);
nextBtn.innerHTML = "Next";
// Randomely pick a question from the array
randomItem = questions[Math.floor(Math.random()*questions.length)];
random = document.getElementById('questions');
random.innerText = randomItem;
counter++;
} else {
alert('No more questions !')
}
});