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

178
Views
Depuración de una tarea de tipo ToDoList en JS

Estoy tratando de hacer una tarea de tipo lista de tareas pendientes que se ejecute en la consola con avisos.

Se piensa de la siguiente manera: Aparece el mensaje y puede escribir una de las siguientes acciones: nuevo elemento / eliminar elemento / enumerar elementos / salir.

El problema es que, por ejemplo, cuando escribo "nuevo" y luego "regresar" (después de terminar la lista), luego, por ejemplo, escribo "lista" (la consola muestra la matriz de la lista), pero cuando quiero volver a escribir "nuevo" (para agregar elementos adicionales), la tarea se cierra.

No puedo ver si me equivoqué en el código... ¿Por qué el ciclo while "nuevo" no se inicia la segunda vez cuando escribo "nuevo"?

Aquí está el código que tengo por el momento:

 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!