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

175
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
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