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

165
Views
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 answers
Answer question

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 Report

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 Report
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!