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

134
Vistas
My while loop is not working on JavaScript

my teacher sent me an excercise and I need help to solve it. It's about making a shopping list. When you press the button cancel, the elements you add should be displayed on the website but it doesn't happen. Please, I need help.

<body>
<h1>SHOPPING EVERYWHERE!</h1>
 <script>
 var lista = prompt('Introduce element to add');
  while (lista != null) {
   document.write('<li>' + lista + '</li>');
   l = prompt('Introduce element to add');
  }
 </script>
</body>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The variable lista will never change in the loop because you never change the variable lista. I think your issue was that you wrote l in the loop and not lista, so may write:

<body>
<h1>SHOPPING EVERYWHERE!</h1>
<script>
 var lista = prompt('Introduce element to add');
  while (lista != null) {
   document.write('<li>' + lista + '</li>');
   lista = prompt('Introduce element to add');
  }
 </script>
</body>

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