Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!