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 ")
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 ");
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 ")