JavaScript: console.log vs alert()

Dpinkston91

Baseband Member
Messages
31
Location
Arkansas City, KS
Could anybody tell me why the 'alert()' works and functions correctly where it's at, but when I replace 'alert()' with 'console.log'... console.log does not display in the console? I do not understand this.

Here is my code:

const myToDo = ['Cook', 'Study', 'Work']
let input = prompt('What would you like to do: (New, List, Delete, Quit)'); //let input = prompt starts our whole 'to-do' list function.
while (input === "New") {
let newToDo = prompt("What would you like to 'ADD' to the list?");
if (newToDo !== undefined) {
alert(`${newToDo} added to the list.`);
}
}
 
What browser are you using??

I’ve had this issue on Chrome in the past. If you are a chrome user, you’ll see a dropdown for the console log levels in the console. By default the level will be “info” meaning that only errors and warnings will be logged.

Ensure you have “verbose” selected to ensure your console.log and console.debug statements work.

Hope this solves your problem ??
 
Currently with Chrome of course.

Located the 'levels' drop-down and selected "Verbose".

The funny thing is that I added the console.log statement underneath the alert statement with the same text written inside and it finally logged it for me in the console (after selecting 'verbose'). Then, I refreshed the page and tried it again and the console.log function did not work. Something seems buggy to me. But, it did work for a time!
 
I've been out of coding for about a week because I'm an idiot, and I just read your post.

However, your advice worked the very first time I tried it out, but now it doesn't appear in the console. Even with all levels selected (verbose included)

Here is my code again, feel free to take a look at it if you want but no worries if you don't... I'm still a little out of it (life trials).

const myToDo = ['Cook', 'Study', 'Work']
let input = prompt('What would you like to do: (New, List, Delete, Quit)'); //let input = prompt starts our whole 'to-do' list function.
while (input === "New") {
let newToDo = prompt("What would you like to 'ADD' to the list?");
if (newToDo !== undefined) {
alert(`${newToDo} added to the list.`);
console.log(`${newToDo} added to the list.`);
}
}
 
Try clearing your cache and then try again? I get that sometimes
I figured it out! haha... let me calm down.

Well, I actually nested every one of those 'if' statements inside the very first one. The console.log ran at the end like I wanted it to now. Thank you for your help, Cheeky!
 
Back
Top Bottom