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

213
Vistas
how to count back with a javascript code?

This is an example exercise to count backwards from 10 to 1. Print the numbers on the screen.

and this is my code:

<script type="text/javascript">
i=1
while( 11 > i ) {
document.writeln("<p>" + i + "</p>");
i--;
}
</script>

I don't know what mistake is in the code but the numbers didn't print on the screen. Also, the browser took awhile to load and I had to stop it. Could someone give an explanation so I can understand how to write this the correct way? Thank you.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

So, as I understood you are trying to add the "p" tag with iteration number to the your document. There are several mistakes in your code:

  1. You did not specify type of the variable "i" In our example, "let" will be best choise.
  2. Your while loop is endless because you are not reassigning "i" variable Your "i--" operation just took the number from variable, then subtracts 1 and does not use the result anywhere. You need to assign the result to another variable or, in this case, overwrite an existing variable
  3. Also, the loop condition is not built correctly. The final result should look like:

let i = 10;
while (i !== 0) {
  document.writeln("<p>" + i + "</p>");
  i = i - 1;
}

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