Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

183
Vistas
cómo arreglar el botón de reinicio que no funciona

Hice una tarjeta flash que mostrará las preguntas que guardé en la matriz y luego haga clic para obtener otras preguntas. Pero tengo un problema si en el medio hago clic en el botón de reinicio. por ejemplo, tengo 6 preguntas y hago clic en reiniciar cuando el progreso es 3, el progreso se restablecerá a 1 y ejecutará la pregunta del 1 al 6, pero en mi código continúa 4 5 6.

 var btnRestart=document.getElementById("restart"); var btnNext=document.getElementById("next"); var words = [{ question: "HTML stands for", answer: "HyperText Markup Language" }, { question: "What is a href?", answer: "Link location attribute" }, { question: "What is extensions used to save HTML pages?", answer: ".html" }, { question: "What type of video formats are supported by HTML5", answer: "MP4, WebM, Ogg" }, { question: "What is _blank target attribute?", answer: "It is opens the document in a new window or tab" }, { question: "How to handle events in HTML?", answer: "Using javaScript or jQuery." }, { question: "What is _parent target attribute?", answer: "It is opens the document in a parent frame" } ]; randomQuestions(); var count = 1; function randomQuestions() { count++; var tempWords = []; for (var i = 0; i < words.length; i++) { tempWords.push(i); } //last question if (tempWords.length === 1) { btnNext.style.display = 'none'; } let index = Math.floor(Math.random() * tempWords.length); const question = words.splice(index, 1)[0] document.getElementById("question").innerHTML = question.question; } btnNext.addEventListener('click', function(){ randomQuestions(); }); btnRestart.addEventListener('click', function() { randomQuestions(); tempWords = []; count = 1; })

HTML

 <div id="question"> <h4>Questions</h4> </div> <button id="next">Next</button> <button id="restart">Restart</button>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Compruebe si esto puede funcionar para usted:

 var btnRestart = document.getElementById("restart"); var btnNext = document.getElementById("next"); const questionElem = document.getElementById("question") var count = 0; var words = [{ question: "HTML stands for", answer: "HyperText Markup Language" }, { question: "What is a href?", answer: "Link location attribute" }, { question: "What is extensions used to save HTML pages?", answer: ".html" }, { question: "What type of video formats are supported by HTML5", answer: "MP4, WebM, Ogg" }, { question: "What is _blank target attribute?", answer: "It is opens the document in a new window or tab" }, { question: "How to handle events in HTML?", answer: "Using javaScript or jQuery." }, { question: "What is _parent target attribute?", answer: "It is opens the document in a parent frame" } ]; let leftWords = [...words] randomQuestions(); function randomQuestions() { if (count === words.length - 1) btnNext.style.display = 'none'; const idx = Math.round(Math.random() * (leftWords.length - 1)) console.log("RANDOM IDX", idx, "QUESTIONS LEFT:", leftWords.length) questionElem.innerHTML = leftWords[idx].question; leftWords.splice(idx, 1) count++; } btnNext.addEventListener('click', randomQuestions); btnRestart.addEventListener('click', function() { btnNext.style.display = 'inline'; count = 0 leftWords = [...words] randomQuestions(); })
 <div id="question"> <h4>Questions</h4> </div> <button id="next">Next</button> <button id="restart">Restart</button>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda