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

130
Visualizações
Ready, steady, go + start timer

My countup function worked satisfactorily. But then I wanted to add ready, steady, go. That is, give the user 3 seconds to shift their attention from the button on the screen to the test on their sheets of paper.

So, what I need: ready, steady, go beeps, then a timer starts counting.

Code

var ready_steady_go_counter = 0;

jQuery(function(){
    jQuery('#timer-form').on('submit', function(event){        
        event.preventDefault();        
        initiate_minutes();

        const ReadySteadyGoPromise = new Promise((resolve, reject) => {
            function ready_steady_go(){
                setTimeout(function () {
                    
                    if (ready_steady_go_counter > 2) { // Ready (0), steady (1), go (2);                        
                        return;
                    } 
                    
                    beep();
                    ready_steady_go_counter++;
                    ready_steady_go(); // <--- this is the "loop"        
                }, 1000);
            }
            ready_steady_go();    
        });        

        ReadySteadyGoPromise.then(countup, function(){console.log("Alert (timer)!")});        
        remove_submit_button();
        show_planned_times();
    });
});


function tick() {
    datediffInms =  new Date() - startDateTime;    
    seconds_lapsed = Math.round(datediffInms / 1000);
}


function countup() { 
    setTimeout(function () { // Breakpoint.
        if (stopped) return;
        if (!is_paused()) {
            tick();
            show_time_left();            
        }
        countup(); // <--- this is the "loop"
    }, 1000);
}

Problem

Ready, steady, go really beeps as planned. But countup doesn't start. I have marked where a breakpoint is situated with // Breakpoint.

So, the interpreter doesn't stop at the breakpoint. This means that counting up has not started.

How can I complete my task?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The promise you are creating needs to resolve for countup to be called, but you never resolve it.

In this part of your code

    if (ready_steady_go_counter > 2) { // Ready (0), steady (1), go (2);                        
                            return;
                        } 

replace return with resolve(); return and it should work.

about 4 years ago · Juan Pablo Isaza 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