javascript javascript控制台日志不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19770560/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 16:44:24  来源:igfitidea点击:

javascript console log not working

javascriptconsole.log

提问by Jill

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:

我是 JS 新手。今天我试图练习一些我学到的东西,但我无法让我的控制台日志打印任何东西。我的“早上好”警报和我最初的提示问题一样有效,但是一旦我回答“是”或“否”,一切都会停止。这是我的代码:

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.

谢谢。

采纳答案by Quentin

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

我根本没有看到任何控制台窗口出现。就好像没有更多的代码写在提示之外

console.logwill write to the console.

console.log将写入控制台。

It will notcause 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.

您必须手动打开浏览器的控制台(开发人员工具,因为您使用的是 Chrome)。

回答by shriniwas_ayyer

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.

不幸的是,IE 具有这种依赖性,只有在您打开它时才会创建控制台对象(F12)。因此,console.log 尝试为对象控制台调用 log 方法,如果尚未创建该对象,则会导致错误。

回答by Anil Kumar M B

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.

在chrome中,有时控制台上可以显示的内容,可以改为“全部隐藏”。要查看必要的内容,请在下拉列表中选择适当的字段。

view image

看图片

回答by Aqeel

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 '语句。它确实适用于三个,但最好使用双等号。您的代码将是:

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.")
}

回答by Aqeel

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 '语句。它确实适用于三个,但最好使用双等号。您的代码将是:

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.")
}

回答by ElGavilan

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

如果开发人员工具 (F12) 未打开,某些浏览器 (IE) 将崩溃: 如何在 Internet Explorer 中使用控制台日志记录?