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

101
Vistas
Why is there an unwanted space in this typewriter function?

This outputs L oading however when i execute this, no compilers errors whatsoever, im so confuzzled, i know how to solve this (just put a space before) but i want to know why its happening

<!DOCTYPE html>
<html>

<body>
  <script>
    var i = 0;
    var txt = 'Loading';

    function type()
    {
      if (i < txt.length) {
        document.body.innerHTML += txt.charAt(i);
        i++;
        setTimeout(type, 50);
      }
    }
    type();
  </script>
</body>

</html>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You're modifying the body element before it's done rendering. If you wait to start typing until after the page has had a chance to fully load (by calling your first type in onload), it will work as expected.

<!DOCTYPE html>
<html>

<body>
  <script>
    var i = 0;
    var txt = 'Loading';

    function type() {
      if (i < txt.length) {
        document.body.innerHTML += txt.charAt(i);
        i++;
        setTimeout(type, 50);
      }
    }
    window.onload = function() {
      type();
    }
  </script>
</body>

</html>

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