[英]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.