console.log不会在我的浏览器中显示文本

时间:2014-07-15 22:55:12

标签: 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 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;

    };

2 个答案:

答案 0 :(得分:0)

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

<强>更新

在评论中,您可以尝试

document.body.appendChild( document.createTextNode("Your message here") );

由enhzflep提供。

document.body.innerHTML += "text"

由Derek提供

答案 1 :(得分:-3)

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