7th Edition Patrick Carey
Notes
1- The file is chapter after chapter.
2- We have shown you 10 or five pages.
3- The file contains all Appendix and Excel
sheet if it exists.
4- We have all what you need, we make
update at every time. There are many new
editions waiting you.
5- If you think you purchased the wrong file
You can contact us at every time, we can
replace it with true one.
Our email:
, Solution and Answer Guide: Carey, JavaScript Web Warriors 7e, 9780357638002, Chapter 1: Introduction to JavaScript
Solution and Answer Guide
Carey, JavaScript Web Warriors 7e, 9780357638002, Chapter 1: Introduction to JavaScript
Table of Contents
Quick Check Answers .................................................................................................................................... 1
Quick Check 1 ............................................................................................................................................ 1
Quick Check 2 ............................................................................................................................................ 2
Quick Check 3 ............................................................................................................................................ 2
Quick Check 4 ............................................................................................................................................ 3
Review Questions Answers ........................................................................................................................... 4
Hands-On Project Solutions .......................................................................................................................... 9
Hands-On Project 1-1 ................................................................................................................................ 9
Hands-On Project 1-2 ................................................................................................................................ 9
Hands-On Project 1-3 ................................................................................................................................ 9
Hands-On Project 1-4 ................................................................................................................................ 9
Hands-On Project 1-5 (Debugging Challenge) ........................................................................................... 9
Case Project Solutions................................................................................................................................... 9
Individual Case Project .............................................................................................................................. 9
Team Case Project ..................................................................................................................................... 9
Quick Check Answers
Quick Check 1
1. How does a scripting language like JavaScript differ from a programming language like C#?
JavaScript does not require a compiler, but instead needs a JavaScript interpreter which
reads and runs the code as it is loaded.
Feedback: Scripting languages like JavaScript differ from programming languages like Java
and C#, which need to be compiled (written for machine code) before they can be run.
2. What are the three core foundations upon which JavaScript is built?
ECMAScript, the Document Object Model (DOM), the Browser Object Model (BOM)
Feedback: ECMAScript is a scripting language that is used by language other than JavaScript.
One of things that makes JavaScript unique is that combines ECMAScript with the Document
Object Model (DOM) that specifies how to interact with the contents of the web page and
the Browser Object Model (BOM) that specifies how to interact with the browser.
3. In client/server architecture, what is a client? What is a server?
© 2022 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible 1
website, in whole or in part.
, Solution and Answer Guide: Carey, JavaScript Web Warriors 7e, 9780357638002, Chapter 1: Introduction to JavaScript
The server is usually some sort of database from which a client requests information. A
server fulfills a request for information by managing the request or serving the requested
information to the client—hence the term, client/server. One of the primary roles of the
client, or front end, in a two-tier system is the presentation of an interface to the user.
The user interface gathers information from the user, submits it to a server, or back end,
then receives, formats, and presents the results.
Feedback: In understanding how JavaScript interacts with the user’s computer and the
computer hosting the website, it’s important to distinguish between the client (the user’s
computer) and the server in which the website resides.
Quick Check 2
1. What HTML element is used to embed JavaScript code within an HTML file?
The script element
Feedback: The <script> tag encloses all JavaScript statements that are embedded within
the HTML file. It is also used to reference external JavaScript files by including the src
attribute within the tag. However, it cannot do both at the same time.
2. What JavaScript command do you use to write the HTML content <h1>Plant Types</h1> to
the web page document?
document.write("<h1>Plant Types</h1>")
Feedback: The document.write() method is used to write content into the web page
at the location in the HTML file where the script element has been placed.
3. Provide the code to write the text, “Major Page Heading” as JavaScript block comment.
/*
Major Page Heading
*/
Feedback: Block comments must start with the /* characters and end with the */
characters. All text between those two characters is treated as comment text.
4. Provide the code to write the text, “Major Page Heading” as a JavaScript line comment.
// Major Page Heading
Feedback: Line comment are single line comments that begin with the // characters. They
can only extend through a single line. If one needs a multi-line comment, one should use a
block comment.
Quick Check 3
1. What are the three JavaScript keywords for declaring a variable?
let, var, and const
Feedback: The let keyword represents the standard introduced in ES6 (in 2016.) The var
keyword is the old standard and is still typically used in JavaScript code. The const
keyword was also introduced in ES6 and should only be used for constants (unchanging
© 2022 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible 2
website, in whole or in part.
, Solution and Answer Guide: Carey, JavaScript Web Warriors 7e, 9780357638002, Chapter 1: Introduction to JavaScript
values.) The main difference between var and let is in the scope of the variable (a topic
introduced in Chapter 2.)
2. What is the difference between declaring and initializing a variable?
Using the let, var, or const keywords to create a variable is called declaring the
variable. When you declare a variable, you can also assign a specific value to, or initialize,
the variable by adding an equal sign ( = ) after the variable name, followed by the value
you’re assigning to the variable.
Feedback: Variables can be declared with or without an initial value. JavaScript, being a
loosely typed language (as discussed in Chapter 2) can be introduced with a formal
declaration, but that is considered poor programming practice.
3. What is returned by expression "100" + 10?
10010
Feedback: When the + operator is used with text strings, it combines the text strings even
if those strings contain numeric values.
4. What is an event handler for?
When an event occurs, your script executes any code that responds to that specific event
on that specific element. This code is known as the event handler.
Feedback: Event handlers are required for JavaScript code to respond to actions or events
occurring within the web page or web browser after the script has been completely loaded.
These events can be such things as a user clicking a form button, text being typed into a
input control, or a form being submitted to the server for processing.
Quick Check 4
1. Why should you place scripts at the end of an HTML document’s body section?
The elements in an HTML document are rendered in the order in which they occur in the
document, and each script is processed when the HTML element that contains it is parsed
by a browser. When processing a script in the head section or in the middle of HTML
content, browsers do not continue rendering the web page until the script is loaded and
executed. If a script is very large or complex, this could cause the page to be displayed
with only some of its content and formatting until the script finishes loading. If you
instead place your script elements just before the end of the body section, you allow
browsers to render all the simple HTML content immediately on the user’s screen, and
then load and process any JavaScript that works with that content. This ensures that users
can see and interact with the entire web page as quickly as possible.
Feedback: By default, when the browser encounters a script it immediately executes the
contents of the script before continuing to load the rest of the web page. If the script needs
to work with elements of the web page as referenced in the Document Object Model, all of
the web page should be loaded and, thus, it is best to put the script at the end of the HTML
© 2022 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible 3
website, in whole or in part.
, Solution and Answer Guide: Carey, JavaScript Web Warriors 7e, 9780357638002, Chapter 1: Introduction to JavaScript
file. However, this can be mitigated for external JavaScript files by placing the defer
attribute in the <script> tag.
2. How do you incorporate the contents of a JavaScript source file into an HTML document?
To access JavaScript code that is saved in an external file, you use the src attribute of the
script element. You assign to the src attribute the URL of a JavaScript source file.
Feedback: When the browser encounters a <script> tag that loads an external JavaScript
file it will immediately load the contents of that file (pausing the loading of the rest of the
web page) unless the defer or async attribute is included with the tag.
Review Questions Answers
1. A programming language like Java requires a:
a. Interpreter
b. Document Object Model
c. compiler
d. Browser Object Model
Answer: C
Feedback: Programming languages which are not interpreted need a compiler to transform
the program code into machine code
2. HTML is an example of a:
a. programming language
b. machine language
c. scripting language
d. markup language
Answer: D
Feedback: A markup language is a language that defines the content, structure, and
appearance of a document.
3. The syntax specifications for JavaScript are defined in:
a. HTML
b. the Document Object Model
c. the Browser Object Model
d. ECMAScript
Answer: D
Feedback: JavaScript is a scripting language based on the standards of ECMAScript which is
constantly developed and adapted to meet the needs of modern browsers and devices.
© 2022 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible 4
website, in whole or in part.
, Solution and Answer Guide: Carey, JavaScript Web Warriors 7e, 9780357638002, Chapter 1: Introduction to JavaScript
4. JavaScript is built upon:
a. ECMAScript
b. the Document Object Model
c. the Browser Object Model
d. ECMAScript, the Document Object Model, and the Browser Object Model
Answer: D
Feedback: JavaScript is built on three foundations: the scripting language ECMAScript, the
Document Object Model (DOM) that describes how to access the contents and actions
within a web page, and the Browser Object Model (BOM) that describes how to access the
features and behaviors of the browser
5. The specifications for the Document Object Model are determined by:
a. each browser alone
b. each device alone
c. the World Wide Web Consortium (W3C)
d. the European Computer Manufacturers Association (ECMA)
Answer: C
Feedback: The specifications of the DOM are maintained by the World Wide Web
Consortium (W3C) which also is responsible for the development of standards for HTML and
CSS.
6. Which of the following is not a language used by web developers?
a. JavaScript
b. HTML
c. CSS
d. machine code
Answer: D
Feedback: Machine code is code that is understand by computers or computer devices.
Programming languages which are compiled translate their commands into machine code.
7. A system consisting of a client and a server is known as a __________.
a. mainframe topology
b. double-system architecture
c. two-tier system
d. wide area network
Answer: C
© 2022 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible 5
website, in whole or in part.
, Solution and Answer Guide: Carey, JavaScript Web Warriors 7e, 9780357638002, Chapter 1: Introduction to JavaScript
Feedback: In traditional client/server architecture, the server is usually some sort of
database from which a client requests information. A system consisting of a client and a
server is known as a two-tier system.
8. What is usually the primary role of a client?
a. locating records that match a request
b. heavy processing, such as calculations
c. data storage
d. the presentation of an interface to the user
Answer: D
Feedback: One of the primary roles of the client, or front end, in a two-tier system is the
presentation of an interface to the user. The user interface gathers information from the
user, submits it to a server, or back end, then receives, formats, and presents the results
returned from the server. In traditional client/server architecture, the server is usually some
sort of database from which a client requests information. A system consisting of a client
and a server is known as a two-tier system.
9. Which of the following functions does the processing tier not handle in a three-tier
client/server system?
a. processing and calculations
b. reading and writing of information to the data storage tier
c. the return of any information to the client tier
d. data storage
Answer: D
Feedback: A three-tier client/server system—also known as a multitier client/server system
or n-tier client/server system—consists of three distinct pieces: the client tier, the
processing tier, and the data storage tier.
10. Which of the following uses the correct case?
a. Document.write()
b. document.write()
c. document.Write()
d. Document.Write()
Answer: B
Feedback: JavaScript objects and methods are written in all lowercase letters.
11. Which of the following is not a valid identifier?
a. $InterestRate
b. 2QInterest Rate
© 2022 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible 6
website, in whole or in part.
, Solution and Answer Guide: Carey, JavaScript Web Warriors 7e, 9780357638002, Chapter 1: Introduction to JavaScript
c. interestRate
d. _interestRate
Answer: B
Feedback: You can use numbers in an identifier but not as the first character.
12. When you assign a specific value to a variable on its creation, you __________ it.
a. declare
b. call
c. assign
d. initialize
Answer: D
Feedback: Before you can use a variable, you declare it which creates the variable for
storing data and objects; optionally, the variable can be initialized which assigns it an initial
value.
13. Code that tells a browser what to do in response to a specific event on a specific element is
called a(n) __________.
a. method
b. event handler
c. response
d. procedure
Answer: B
Feedback: When an event occurs, your script executes any code that responds to that
specific event on that specific element. This code is known as the event handler.
14. Which method displays a dialog box with an OK button?
a. document.write()
b. document.writeln()
c. window.alert()
d. window.popup()
Answer: C
Feedback: The window.alert() method displays a dialog box with an OK button.
15. Which of the following is not a JavaScript keyword used to declare a variable?
a. variable
b. var
c. let
© 2022 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible 7
website, in whole or in part.
, Solution and Answer Guide: Carey, JavaScript Web Warriors 7e, 9780357638002, Chapter 1: Introduction to JavaScript
d. const
Answer: A
Feedback: Variables are declared using the var, let, or const keywords. If the script
references page elements which have not been loaded by the browser an error will result
and the script will fail to run.
16. What potential problems can occur if you load a script prior to the page being entirely
loaded by the browser?
If the JavaScript program attempts to reference a page element prior to that element
being loaded by the browser, an error will result.
17. How can you make the browser not parse and load an external script file until after the page
has loaded?
Add the defer attribute to the <script> tag.
18. When should you use an external JavaScript file instead of embedding your JavaScript code
within the HTML file?
There are several situations where this is preferable: a) When you need to share code
among several different web pages, b) When you working in a team with different team
members responsible for different aspects of the website development (such as content,
design and layout, and programming) and you want to keep those files separate, and c) In
order to dedicate documents to the tasks for which they are design with HTML files solely
focused on page content and structure, CSS files focused only on page layout and design,
and JavaScript files dedicated only to programming-related tasks.
19. Provide the JavaScript code to write the text “Copyright 2023” as a line comment. Provide
the code to write the same text as a block comment.
// Copyright 2023
/*
Copyright 2023
*/
20. What is a library?
In addition to storing scripts for multiple pages in the same website, sometimes JavaScript
source files store especially useful generic scripts used on many different websites. These
files, known as libraries, are often developed by a single programmer or a team of
programmers and distributed online. Many libraries are developed to solve a problem on
one website and turn out to be useful for other sites as well. Programmers often make
libraries available for free reuse.
© 2022 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible 8
website, in whole or in part.