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

183
Views
While loop not looping (Javascript)

Simple question here. I am slowly building a to do list program. Whilst you do not quit I would like to the program to keep looping. But it keeps asking 'What is the to do text' after it is inputted?

Whereas I would like it to loop back to the beginning 'What would you like to do' so I can add additional functions such as: list the to do's Delete a to do

Code below:

while (input.toLowerCase() !== 'quit') {

    const list = [];

    if (input === 'new') {
        let todo = prompt('What is the to do text')
        list.push(todo);
        
    }

    }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you need to define input first and i would put the list outside the while loop because if you dont the list get overwritten each time.

let input = ''
const list = [];
while (input.toLowerCase() !== 'quit') {
    input = prompt('What do you want to do?')
    if (input === 'new') {
        let todo = prompt('What is the to do text')
        list.push(todo);
    }
}
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!