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

171
Views
Debugging a ToDoList type task in JS

A am trying to make a todolist type task that runs in the console with prompts.

It is thought like following: Prompt shows and you can type one of the following actions: new item / delete item / list items / quit.

Problem is that for example when i type "new" then "return" (after finishing the list) then for ex i type "list" (console displays the list array), but when i want again to type "new" (to add adional items) , the task closes.

I can't see were i am wrong in the code... Why doesn't the "new" while loop launch the 2nd time when i type "new" ?

Here is the code i have for the moment:

let input = prompt("Welcome to TO-DO-LIST! Please chose an action : 1. Add item - type 'new' / 2. List all todos - type 'list' / 3. Remove a specific todo - type 'delete' / 4. Quit - type 'quit'")

const list = [];

// NEW ITEMS FUNCTION
while (input === 'new'){
  let item = prompt("What would you like to do? Type 'return' to go back to main menu");
  if(item === 'return'){
    input = prompt("Welcome to TO-DO-LIST! Please chose an action : 1. Add item - type 'new' / 2. List all todos - type 'list' / 3. Remove a specific todo - type 'delete' / 4. Quit - type 'quit'")
  }else{
    list.push(item);
  }
}

// REMOVE ITEMS FUNCTION
while(input ==='delete'){
  let removeItem = prompt("What would you like to remove? Type 'return' to go back to main menu")
  if(removeItem === 'return'){
    input = prompt("Welcome to TO-DO-LIST! Please chose an action : 1. Add item - type 'new' / 2. List all todos - type 'list' / 3. Remove a specific todo - type 'delete' / 4. Quit - type 'quit'")
  }else{
    list.splice(0, 1, removeItem);
  }
}

// QUIT FUNCTION
if(input==='quit'){
  console.log("You have exited the list");
}

// SHOW LIST FUNCTION
while(input ==='list'){
  console.log('---------');
  for(let i = 0; i < list.length; i++){
    console.log(`${i}: ${list[i]}`);
  }
  console.log('---------');
  input = prompt("Welcome to TO-DO-LIST! Please chose an action : 1. Add item - type 'new' / 2. List all todos - type 'list' / 3. Remove a specific todo - type 'delete' / 4. Quit - type 'quit'")
}
about 4 years ago · Juan Pablo Isaza
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!