Hola, tengo un cuestionario que hice con JavaScript y tengo una matriz de preguntas. Quiero mostrar aleatoriamente preguntas de la matriz, pero no quiero que las preguntas se repitan, así que creé otra matriz para las preguntas usadas y cada pregunta que se hace. está en la matriz. y traté de verificar si la nueva pregunta está en la matriz antes de que se imprima, pero no funciona. ¿Cómo puedo mostrar aleatoriamente preguntas de la matriz sin repetirlas?
function randomize() { let random = Math.floor(Math.random() * questions.length); return random; } let usedQuestions = [10]; submit.addEventListener("click", function(){ if(questionNumber == questions.length - 1){ question.style.display = "none"; answer.style.display = "none"; submit.style.display = "none"; card.style.display = "block"; score.innerText = "Your score is " + points + "/" + questions.length * 10; //stop the function from running return; } let userAnswer = document.getElementById("answer").value; if(userAnswer == answers[questionNumber]){ points +=10; console.log("correct"); } else{ console.log("incorrect" + " " + "the correct answer is " + answers[questionNumber]); //if(points == 10){ //points = 0; //} } //in the else I check if the user have more than 10 points and if so I decrement the points by 10 but id no then I set the points to 0 questionNumber++; answer.value = ""; counter++; usedQuestions[questionNumber] = questions[randomize()]; function check(){ for (let i = 0; i < usedQuestions.length; i++) { if(usedQuestions[i] == randomize()){ randomize(); check(); } } } check(); //question.innerText = questions[questionNumber]; question.innerText = questions[randomize()]; });