为什么我的输出重复?

Why is my output repeating?

我想提醒 "running function cannons" 然后当我按确定时我只想说 "cannon ship sails off to 14 degrees" 但它一直在我的输出中打印警报。

JS

function alertMessage (message) {
alert (message);
}
alertMessage("the Battle has begun");



function alertShip (ship, number) {
alert (ship);
document.write (ship + "the ship sails off to " + number + "degrees");

}
alertShip("running function cannons", 14);

HTML

<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="utf-8">
  <title>Functions</title>

    <!-- This links to the js code specific for this page -->
    <script src="functions.js"></script>
</head>
<body>



  <div id="output"> </div>  
 <div id="output2"> </div>  

</body>
</html>

不要给他们相同的变量来输出.. alert (ship) 然后 document.write (ship+.....)。 试试这个

function alertShip (ship, number) {
alert (ship);
document.write ("Cannon ship sails off to " + number + "degrees");

尝试从 document.write 中删除 ship 参数并将语句替换为:

document.write("cannon ship sails off to " + 数字 + "度数");

那么,你应该能够得到你想要的输出。

*p.s.: 如果您在文本编辑器上执行此操作并尝试在浏览器上执行此操作 运行,您可以考虑将标签更改为:.

希望对您有所帮助!