gpt4 book ai didi

javascript - 我的 javascript 没有显示在我的浏览器中?

转载 作者:行者123 更新时间:2023-11-28 06:09:00 25 4
gpt4 key购买 nike

详细信息:所以基本上我是一个 JS 菜鸟。当我在 chrome 中打开它时,除了 H1 标题之外什么也没有发生。请帮忙。

HTML 文件代码。 <!doctype HTML> <html> <head>

</head>

<body> <h1> Welcome to battleship! </h1> <script type="text/javascript" src="battleship.js"></script>

</body>

</html>

JavaScript 代码。名称是“battleship.js”,以防万一您想知道。

//location of ship
var location1 = 3;
var location2 = 4;
var location3 = 5;

//number of guesses
var guess;
var guesses = 0;
var hits = 0;

//is the ship sunk?
var isSunk = false;

while (isSunk == false) {
guess = prompt("Ready, aim, FIRE! Enter a number 0 - 9 to hit the ship!");

if (guess > 6 || guess < 0) {
alert("Please enter a valid number fool!");
} else {
guesses = guesses + 1;
}
if (guess == location1 || guess == location2 || guess == location3) {
hits = hits + 1;
if (hits == 3) {
alert("You sank my B ship hombre");
}
}
}
}
var stats = "You took " + guesses + " guesses to sink the battleship. Your accuracy is " + (3/guesses);

最佳答案

检查您的脚本和 HTML 文件是否存储在同一文件夹中,并检查您的脚本是否有任何错误。如果脚本有任何错误将不会按预期执行。

看来你在脚本末尾多写了一个}

关于javascript - 我的 javascript 没有显示在我的浏览器中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36589152/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com