Javascript console.log不';t在我的浏览器中显示文本

Javascript console.log不';t在我的浏览器中显示文本,javascript,browser,console.log,Javascript,Browser,Console.log,我不熟悉编码,但我想你可以在这里帮助我。我想要的是在实际网页上打印的代码,但这并不是我做错了什么,或者我只是误解了console.log代码 switch(user){ case 'FIGHT': console.log("You choose to fight the man who robbed you."); var fight = prompt("Do you choose your RIGHT HAND or LEFT HAND to hit the th

我不熟悉编码,但我想你可以在这里帮助我。我想要的是在实际网页上打印的代码,但这并不是我做错了什么,或者我只是误解了console.log代码

   switch(user){
   case 'FIGHT': 
    console.log("You choose to fight the man who robbed you.");
    var fight = prompt("Do you choose your RIGHT HAND or LEFT HAND to hit the theif     with?","Choose you answer here, RIGHT HAND or LEFT HAND?").toUpperCase(); 

    switch(fight) {
    case 'RIGHT HAND':
        console.log("You choose your right hand, the strongest and most buffest arm you have(Yes you are an octopus in this game), you hit the theif and he flies at least one mile away. But you got your stuff back. Congratz!")
    break;

    case 'LEFT HAND': 
        console.log("You choose the left hand, the weakest arm you have. You punch the theif, but instead of damaging him, you break your hand and dies.");
    break;

    default: 
        console.log("You didn't type a legit answer, now the theif killed you. Try       again.")
    break;

    };

console.log
输出到javascript控制台。在大多数浏览器中,它位于开发人员工具(通常是F12)中的某个位置

更新

如评论中所述,您可以尝试

document.body.appendChild( document.createTextNode("Your message here") );
由enhzflep提供


Derek提供的console.log将消息输出到浏览器控制台,例如,在Google Chrome中按F12可访问该控制台。
要在页面上输出文本,您可能必须使用jQuery、KnockoutJS或其他数据绑定库

是的,您误解了;它登录到控制台。登录到一个实际的网页是非常困难的。好吧,那么我该如何让它进入网页呢?有我能用的代码吗?所以,也许我应该稍后继续学习?console.log仅用于调试。这取决于您希望它如何进入网页。那里已经有一个页面了吗,或者所有的交互都是通过
提示符
完成的吗?然后学习如何在您喜爱的浏览器中查看控制台。令人惊讶的是,巨大的客户端MV*库并不是写入页面的唯一方式。至少knockoutjs允许以漂亮的方式进行,学习
文档并不难。认真地写
对于如何进入控制台来说+1,-1对于
文档来说。写
-总的来说是0。将文本节点附加到文档中很容易——不需要提倡一种删除正文中所有现有内容的方法。更好:
document.body.appendChild(document.createTextNode(“此处的消息”)
文档。写
是可怕的建议。。。如果在页面加载后使用,它将清除页面
document.body.innerHTML+=“text”
就足够了IMO@Derek朕會功夫: 如果您想低效地关闭所有现有的事件侦听器,请确定。
document.body.innerHTML += "text"