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

217
Visualizações
Web page displays and animated times table

Hi everyone I am currently stuck trying to debug my program. MY goal is for whenever the button "Start Animation" is clicked, the web page displays an animated times table according to the number that the user enters in the text field in the following manner. For example, if the user entered the number 6 in the text field, then the animation displays 1 x 6 = 6, one second later it replaces it with 2 x 6 = 12, one second later it replaces it with 3 x 6 = 18, etc. If it is 9 x 6 = 54, then one second later it becomes 1 x 6 = 6, and then 2 x 6 = 12, and so on.

var counter;
var animationOn = false;
var counterAnimation;

function updateAnimation() {

  var value = document.getElementById('value1').value;

  for (var i = 1; i < 1000; i++) {
    for (var j = 1; j < 10; j++) {
      var product = j * value;
      var counterSpan = document.getElementById("counterHolder");
      counterSpan.innerHTML = product;
    }
  }
  counterAnimation = setTimeout(updateAnimation, 1000);

}

function startAnimation() {
  if (animationOn == false) {
    animationOn = true;
    counter = 1;
    counterAnimation = setTimeout(updateAnimation, 1000);
  }
}

function stopAnimation() {
  if (animationOn == true) {
    animationOn = false;
    clearTimeout(updateAnimation);
  }
}
<body>
  <button onclick="startAnimation();">
        Start animation 
    </button>
  <button onclick="stopAnimation();">
        Stop animation
    </button><br><br>
  <label>Enter an integer: </label>
  <input type="number" size=20 id=value1 name="value">
  <span id="counterHolder">0</span>
</body>

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

0

Edited

Here is a complete solution which makes changes displayed value by time

let counter;
let animationOn = false;
let counterAnimation;
let mult = 1;
        
function updateAnimation() {
  let value = document.getElementById('value1').value;
  let counterSpan = document.getElementById("counterHolder");
  if (mult >= 10) {
    mult = 1;
    counter = null;
    animationOn = false;
    counterAnimation = null;
    counterSpan.innerHTML = 0;
    return;
  }

  let product = mult * value; 
  counterSpan.innerHTML = product;
  mult++
   counterAnimation = setTimeout(updateAnimation, 1000)
}

function startAnimation() {
  if (!animationOn) 
  {
    animationOn = true;
    counter = 1;
    counterAnimation = setTimeout(updateAnimation, 1000);
  }
}

function stopAnimation() {
  if (animationOn) 
  {
    animationOn = false;
    clearTimeout(counterAnimation);
    mult = 1
    counter = null
    animationOn = false
    counterAnimation = null
  }
}
<body>
  <button onclick="startAnimation();">
        Start animation 
    </button>
  <button onclick="stopAnimation();">
        Stop animation
    </button><br><br>
  <label>Enter an integer: </label>
  <input type="number" size=20 id=value1 name="value">
  <span id="counterHolder">0</span>
</body>

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