我想提醒“运行功能大炮”然后当我按下确定时我只想说“大炮航行到14度”但它会在我的输出中保持打印警报。
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>
答案 0 :(得分:2)
尝试从document.write中删除ship参数,并将该语句替换为:
document.write(“cannon ship sails off”+ number +“degrees”);
然后,您应该能够获得所需的输出。
* p.s。:如果您在文本编辑器上执行此操作并尝试在浏览器上运行此操作,则可以考虑将标记更改为:。
我希望这有帮助!
答案 1 :(得分:1)
不要给他们相同的变量输出.. alert(ship)然后document.write(ship + .....)。 试试这个
function alertShip (ship, number) {
alert (ship);
document.write ("Cannon ship sails off to " + number + "degrees");