Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

213
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda