简体   繁体   English

运行代码时浏览器显示空白页

[英]Browser displaying blank page when I run my code

This is probably a very silly question but when I try to run my code in Notepad++ on either browser such as Chrome and IE. 这可能是一个非常愚蠢的问题,但是当我尝试在Chrome和IE等浏览器上的Notepad ++中运行代码时。 It's not showing. 没有显示。 I have carefully looked at the code to see if i'm missing anything but I can't seem to figure out what. 我仔细查看了一下代码,看是否遗漏了任何东西,但似乎无法弄清楚。

I recently asked a question about help on my code and it got fixed, it was working when I ran the "Run code snippet" thingy but when I copied the code to my Notepad++, it's not working. 我最近问了一个有关代码帮助的问题,该问题已得到解决,当我运行“运行代码片段”时,它确实起作用了,但是当我将代码复制到Notepad ++时,它却无法工作。 This is my code... 这是我的代码...

<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript" src="gamescript.js">
</head>

<body>
<p id ="door"> Which door do you wish to enter? Door 1 or Door 2? </p>

<input id="myInput" type="text">

<button onclick="myFunction()">Enter</button>

<!---- Question 1 ---->
<p id ="choice1">Behind Door 1 is an empty room. Whilst searching the room for clues, you see a hidden passageway. Do you wish to enter the passageway or continue searching?</p>

<div id="question2">
<input id="myInput2" type="text">

<button onclick="myFunction2()">Enter</button>
</div>


<!---- Boss ---->
<div id="question3">
<h1>Fight the Monster!</h1>

<p id="mspace"></p>

<div id="game">

  <button id="fight">Fight</button>
  <button id="run">Run</button>

</div>
</div>


</body>
</html>

.

document.getElementById("choice1").style.visibility = "hidden";
document.getElementById("question2").style.visibility = "hidden";
document.getElementById("question3").style.visibility = "hidden";

function myFunction(){
    var door = document.getElementById("myInput").value;
    if (door == "Door 1" || door == "door 1"){
        document.getElementById("door").innerHTML = "You have entered " + door;
        document.getElementById("choice1").style.visibility = "visible";
document.getElementById("question2").style.visibility = "visible";
    }else if (door == "Door 2" || door == "door 2"){
        document.getElementById("door").innerHTML = "You have entered " + door;
        document.getElementById("choice1").style.visibility = "visible";
document.getElementById("question2").style.visibility = "visible";
    }else{
        document.getElementById("door").innerHTML = "You must enter a door!"
    }
}

function myFunction2(){
    var choice1 = document.getElementById("myInput2").value;
    if (choice1 == "enter passageway" || choice1 == "passageway"){
        document.getElementById("choice1").innerHTML = "You entered the " + choice1;
        document.getElementById("question3").style.visibility = "visible";
     }else if (choice1 == "continue searching"){
        document.getElementById("choice1").innerHTML = "You " + choice1; 
        document.getElementById("question3").style.visibility = "visible";
    }else{
        document.getElementById("choice1").innerHTML = "You must choose an option!"
    }
}

// JS for BOSS level
// starting variable for the boss
var stamina = 10;

// starting message
var msg = "A huge, threatening monster wants to fight you! What do you do?";
// run a function that is below
document.getElementById("mspace").innerHTML = msg;

// click a button to execute a function
// NOTE: no parentheses after the function name in these cases
window.onload = function(){
    document.getElementById("fight").onclick = fightResponse;
    document.getElementById("run").onclick = runResponse;
}

function runResponse() {
  if (stamina > 8) {
    msg = "The monster swings his long arm and -- GAME OVER!";
    hideButtons();
  } else if (stamina > 3) {
    msg = "Well, that's one way to end a fight ...";
    hideButtons();
  } else {
    msg = "Keep fighting! The monster is almost dead!";
  }
  writeMessage();
}

function fightResponse() {
  if (stamina > 8) {
    msg = "The monster is strong! It resists your attack!";
  } else if (stamina > 5) {
    msg = "With a loud screech, the monster stands firm.";
  } else if (stamina > 3) {
    msg = "Your attack seems to be having an effect! The monster stumbles!";
  } else if (stamina > 0) {
    msg = "This monster is about to fall! It staggers and reels!";
  } else {
    msg = "With a final swing! The monster has been defeated! You have triumphed!";
    hideButtons();
  }
  // create new random number from 0 to 5
  var damage = Math.floor(Math.random() * 6);
  // subtract it from stamina
  stamina -= damage;
  writeMessage();
}

function hideButtons() {
  // changes the class on the div - see the CSS pane 
  document.getElementById("game").className = "hideThis";
}

function writeMessage() {
  document.getElementById("mspace").innerHTML = msg;
}

I tried using the F12 developer tool but no errors are showing. 我尝试使用F12开发人员工具,但未显示任何错误。 I don't know why it's not working on Notepad++. 我不知道为什么它不能在Notepad ++上运行。 All help is always appreciated and thank you very much! 总是感谢所有帮助,非常感谢!

I think you need to add a </script> so this 我认为您需要添加</script>

<script type="text/javascript" src="gamescript.js" >

becomes this: 变成这个:

<script type="text/javascript" src="gamescript.js" ></script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我简单的jQuery代码无效。 我运行它时会得到一个空白页面 - My simple code of jQuery is not working. I get a blank page when I run it 为什么关闭JavaScript时浏览器显示空白页 - Why browser displaying blank page when javascript turned off 为什么当我在 Apache 上运行我的 React 构建时......只出现空白页面......? - Why is that when i run my react build on Apache...Just blank page appears..? 我的代码将在代码笔中运行,但在打开.html文件时不在浏览器中运行吗? - My code will run in code pen, but not in the browser when I open a .html file? 我的 JavaScript 代码在运行时没有显示任何内容是否有原因? - Is there a reason my JavaScript code isn't displaying anything when I run it? 我只是使用gruntjs构建了AngularJS项目,但是当将结果加载到浏览器中时,我得到了一个空白页面,如何开始对此进行调试? - I just built my AngularJS project using gruntjs, but when I load the result in my browser, I get a blank page, how do I begin debugging this? 帆布屋。 将代码复制到编辑器并在浏览器中运行时,为什么代码不起作用? - Canvas- house. Why isn`t the code working, when I copy it to an editor and run it in my browser? 当我运行此Javascript代码时,为什么浏览器仍然崩溃? - Why does my browser keep crashing when I run this Javascript code? 我在 Apache 服务器上运行 ReactJS 构建时的空白页面 - Blank page when I run ReactJS build on Apache server 为什么运行代码时为什么我的json数据不会出现在浏览器中 - Why my json data wont appear in browser when i run the code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM