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

172
Vistas
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
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