Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

173
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda