Workshop
The workshop contains quiz questions and exercises to help you solidify your understanding of the material covered.
Quiz
When a user views a page containing a JavaScript program, which machine actually executes the script?
The user’s machine running a web browser
The web server
A central machine deep within Netscape’s corporate offices
A dedicated JavaScript server
What software do you use to create and edit JavaScript programs?
A browser
A text editor
A pencil and a piece of paper
A JavaScript editor
What are variables used for in JavaScript programs?
Storing numbers, dates, or other values
Varying randomly
Causing high-school algebra flashbacks
Changing the output of the script
What should appear at the very end of a JavaScript script embedded in an HTML file?
The <script> tag
The </javascript> tag
The END statement
The </script> tag
Which of these is not something you can do with JavaScript?
Detect the features of the browser in use
Modify part of a page without requiring a page refresh
Write data to the remote server
Interact with data from a remote server
Where can you place scripts?
In the body of a page
Within an HTML tag
In a separate file
All of the above
What do you use to include a separate script file in a page?
<link src="filename.js">
<script src="filename.js"></script>
<javascript src="filename.js">
<include src="filename.js"></include>
Which of these is an event handler?
<button>
type="button"
onclick="alert('You clicked the button.')"
</button>
What does the line now = new Date(); do in JavaScript?
It creates a variable called now and stores the current date in it.
It creates a variable called new and stores the current date in it.
It displays the current time.
Nothing; it’s not valid JavaScript.
Correct this line of JavaScript:
document.write("<p><strong>Dinner Time:</strong> " + localtime + "</p>);
document.write("<p><strong>Dinner Time:</strong> " + localtime + "</p>");
document.write("<p><strong>Dinner Time:</strong> " + localtime + "</p>');
document.write("<p><strong>Dinner Time:</strong> " + localtime + "</p>;
The line is correct as written.
Answers
a. JavaScript programs execute in the web browser. (There is actually a server-side version of JavaScript, but that’s another story.)
b. You can use any text editor to create scripts.
a. Variables are used to store numbers, dates, or other values.
d. Your script should end with the </script> tag.
c. JavaScript can never write data to the remote server due to security concerns.
d. JavaScript can be added in the body, a tag, or in a separate file.
b. Use the line <script src="filename.js"></script>.
c. The onclick attribute and its value are the click event handler.
a. It creates a variable called now and stores the current date in it.
a. The final quotation mark is missing.