سؤال

I am new to JS. Today I was trying to practice a little of what I've learned, and I can't get my console log to print anything. My "good morning" alert works, as well as my initial prompt question, but once I answer "yes" or "no," everything stops. Here is my code:

alert("Good morning!");

var hireMe = prompt("Are you here because you're interested in hiring me?");

if (hireMe === "yes") {
console.log("You've just made my day. Carry on.")
}

else {
    console.log("Well, I hope you're at least thinking about it.")
}

Thanks.

هل كانت مفيدة؟

المحلول

I don't see any console window appear at all. It's as if no more code is written beyond the prompt

console.log will write to the console.

It will not cause the console window to open if it isn't already open.

You have to open your browser's console (the Developer Tools since you are using Chrome) manually.

نصائح أخرى

Some browsers (IE) will crash if the developer tools (F12) are not open: How can I use console logging in Internet Explorer?

IE unfortunately has this dependency where the console object gets created only when you open it (F12). So console.log tries to call the log method for the object console, and if that object is not yet created, it results in an error.

In chrome, sometimes the content that can be displayed on the console, can be changed to "Hide All". To view the necessary content, select the appropriate fields in the drop down.

view image

Take a look at your ' if ' statement. It does work with three but it's better to use double equals. Your code will be:

alert("Good morning!");

var hireMe = prompt("Are you here because you're interested in hiring me?");

if (hireMe == "yes") {
console.log("You've just made my day. Carry on.")
}

else {
    console.log("Well, I hope you're at least thinking about it.")
}

Take a look at your ' if ' statement. It does work with three but it's better to use double equals. Your code will be:

if (hireMe == "yes") {
console.log("You've just made my day. Carry on.")
}

else {
    console.log("Well, I hope you're at least thinking about it.")
}

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top