jjdouble000 jjdouble000 - 6 months ago 6
Javascript Question

Why is my output repeating?

I want to alert "running function cannons" then when I press ok I want it just to say "cannon ship sails off to 14 degrees" but it keeps printing the alert within my output.

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>

Answer

don't give them the same variable to output .. alert (ship) then document.write (ship+.....). Try this instead

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