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

164
Visualizações
I am facing two problems. this code supposed to print the 'to do' list

first problem is I have to type 'q' or 'quit' over 2 times to get the console.log("OK! You have quitted the app ") printed in console. Other one is I can not see the todo list printed when I type 'list' until I quit that means I type 'q' or 'quit'. please can anyone solve these problem?

let input = prompt("What would you like to do?");
const toDo = ['Visit Resham', 'Check progress of Barth certificate'];

while (input !== 'quit' && input !== 'q') {

  if (input === 'list') {
    prompt("List has been printed! ")
    console.log('******************')

    for (let i = 0; i < toDo.length; i++) {
      console.log(`${i} : ${toDo[i]}`);
    }

    console.log('*****************')
  }
  input = prompt("What would you like to do?")
}
console.log("OK! You have quitted the app ")

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I just edited your code a little and hope it will work now.

let input = prompt("What would you like to do?");
const toDo = ["Visit Resham", "Check progress of Barth certificate"];

while (input !== "quit" && input !== "q") {
  if (input === "list") {
    console.log("******************");

    for (let i = 0; i < toDo.length; i++) {
      console.log(`${i} : ${toDo[i]}`);
    }

    console.log("*****************");
    alert("List has been printed! ");
  }
  input = prompt("What would you like to do?");
}
console.log("OK! You have quitted the app ");

about 4 years ago · Juan Pablo Isaza Relatório

0

You prompt the user in your if statement, which could be replaced with an alert instead... but if you want to keep it, simply put the prompt outside of the if inside an else.

let input = prompt("What would you like to do?");
const toDo = ['Visit Resham', 'Check progress of Barth certificate'];

while (input !== 'quit' && input !== 'q') {

  if (input === 'list') {
    //alert("List has been printed! ")
    input = prompt("List has been printed! ")
    console.log('******************')

    for (let i = 0; i < toDo.length; i++) {
      console.log(`${i} : ${toDo[i]}`);
    }

    console.log('*****************')
  }
  else
  {
    input = prompt("What would you like to do?")
  }
}
console.log("OK! You have quitted the app ")

about 4 years ago · Juan Pablo Isaza Relatório
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