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

220
Vistas
button click prevents second sound playing

I have a simple Javascript program that plays a sound when correct button is clicked in response to a question. If the user answers a second question too quickly and clicks a second correct answer the sound doesnt play a second time as first play has not completed. Do I need to disable the answer buttons for the duration of the sound? Any other ways roound? Suggestions please

Scruffy code added 27.9.2022

        function setQuestion(){
            // string question 
            var questionText =" x 3 = ";
            questionText=aTimes[index]+ questionText;
            document.getElementById("Question").innerHTML= questionText;
            aAnswers[0]=(aTimes[index]*3);
            aAnswers[1]=Math.floor((Math.random() *10) *(aTimes[index] + 1));
            aAnswers[2]=Math.floor((Math.random() *10) * (aTimes[index] + 2));
            shuffleArray(aAnswers)
            document.getElementById("Answer1").innerHTML= aAnswers[0];
            document.getElementById("Answer2").innerHTML= aAnswers[1];
            document.getElementById("Answer3").innerHTML= aAnswers[2];
        }
        function answerCheck(poss){
            //*****************************************************************                                                     
            //***   does the button clicked match the correct multiple of 3                                                 
            //*****************************************************************                                                 
           if (poss.innerHTML==(aTimes[index]*3) ) {
              changePicture();
              index=(index+1);
              **playAudio();**
              resetButtons();
              setQuestion() ; 
              if (index==10){
                  alert("done");
              }
            }
            else{
               alert("not a match");
               poss.style.backgroundColor = "grey";    
            }
        }
        function resetButtons(){
             document.getElementById("Answer1").style.backgroundColor = "#008CBA" ;
            document.getElementById("Answer2").style.backgroundColor = "#008CBA";
            document.getElementById("Answer3").style.backgroundColor = "#008CBA";
        }
        **function playAudio()** { 
        //************** Play a reward sound 
            var x = document.getElementById("myAudio"); 
            x.play(); 
        } 
        </script>

almost 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The HTML audio element probably isn't a great fit for what you want to do here. I'd recommend using a library like Howler.

almost 4 years ago · Santiago Trujillo 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