Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
elija el índice aleatorio de la matriz y muéstrelo una vez

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()]; });

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!