// this is a short JavaScript program
alert("Hello there!");
alert("Welcome to JavaScript!);
alert("Have a nice day!";Answer: First, the second alert needs an end quotation mark after the string. It should appear as follows:
alert("Welcome to JavaScript!");
Second, the final alert needs an end parenthesis to complete the alert function.
alert("Have a nice day!");
Finally, it's not clear whether this JavaScript is contained within a .js file or an HTML file. If it is in a .js file, no additional markup is needed. If it's in an HTML file, it will need to have a script tag surrounding it:
<script type="text/javascript" language="JavaScript">
// this is a short JavaScript program
alert("Hello there!");
alert("Welcome to JavaScript!");
alert("Have a nice day!");
</script>
Which of the following does not refer to functions or methods?
alert(); confirm(); prompt(); toUpperCase();
wts/asst2 you created in Exercise 2.Actually, the code will run fine with the addition of just two quotation marks, as marked in bold below. Click here to run the script.
<html>
<head>
<title>Poetry Reading</title>
</head>
<body>
<script type="text/javascript" language="JavaScript">
// get the user's response and store it as "goOn"
var goOn;
goOn = confirm("Press OK if you want to read poetry");
/* if they answered "OK", give them poetry
if they answered "Cancel", no poetry */
if (goOn == true)
{
alert("I never saw a purple cow");
alert("I never hope to see one");
alert("But I can tell you anyhow");
alert("I'd rather see than be one");
}
else
{
alert("OK, no poetry today.");
}
</script>
</body>
</html>