Deck 9: Additional Javascript Basics: Window Object, If Statement, Strings, Numbers, and Input Validation
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/30
Play
Full screen (f)
Deck 9: Additional Javascript Basics: Window Object, If Statement, Strings, Numbers, and Input Validation
1
When should you use dialog boxes (alert, confirm, and prompt) for input and output?
A) Dialog boxes are new with HTML5 and, as such, they are gaining traction as the preferred technique for all input and output.
B) Use dialog boxes only when you want to draw sharp attention to something and you want to force the user to deal with the issue immediately.
C) Use dialog boxes for all text input, but not for numerical input.
A) Dialog boxes are new with HTML5 and, as such, they are gaining traction as the preferred technique for all input and output.
B) Use dialog boxes only when you want to draw sharp attention to something and you want to force the user to deal with the issue immediately.
C) Use dialog boxes for all text input, but not for numerical input.
B
2
Consider the following three strings:
"to be or not to be", "to", "tooth"
Which of the following shows the strings sorted into ascending lexicographical order (words that are considered less than other words should be at the left).
A) "to be or not to be", "to", "tooth"
B) "to", "tooth", "to be or not to be"
C) "to", "to be or not to be", "tooth"
"to be or not to be", "to", "tooth"
Which of the following shows the strings sorted into ascending lexicographical order (words that are considered less than other words should be at the left).
A) "to be or not to be", "to", "tooth"
B) "to", "tooth", "to be or not to be"
C) "to", "to be or not to be", "tooth"
C
3
To embed a backslash character (\) within a JavaScript string, you need to use the ______ escape sequence.
\\
4
Provide a functionally equivalent, shorter version of the following code:
window.document.getElementById["name"]
window.document.getElementById["name"]
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
5
The following code generates a dialog box that contains a question and an input box:
prompt("What's your favorite color?", "");
Initially, what displays inside the input box?
prompt("What's your favorite color?", "");
Initially, what displays inside the input box?
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
6
Suppose a variable x holds "dog". After the following code gets executed, what does x hold?
x += "fish";
x += "fish";
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
7
When the following code executes, what message does the dialog box display?
var month = "January";
if (month.toLowerCase() == "january") {
alert("It is " + month + "!");
}
var month = "January";
if (month.toLowerCase() == "january") {
alert("It is " + month + "!");
}
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
8
After the following code executes, what does x hold?
var location = "Taos, NM";
var x = location.charAt(location.length - 1);
var location = "Taos, NM";
var x = location.charAt(location.length - 1);
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
9
After the following code executes, what does x hold?
var animal = "porcupine";
var x = animal.lastIndexOf("p", 3);
var animal = "porcupine";
var x = animal.lastIndexOf("p", 3);
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
10
What does the following expression evaluate to?
39 % 10 / 4
39 % 10 / 4
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
11
Which of the following is a function of the <code>window</code> object's <code>location</code> property?
A) Holds the URL of the current web page
B) Displays the title of the current web page
C) Displays the geographical position of the user's computer
A) Holds the URL of the current web page
B) Displays the title of the current web page
C) Displays the geographical position of the user's computer
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
12
What is the syntax for generating a dialog that displays a message and does not receive input?
A) <code><msg>message</msg></code>
B) <code><quote>message</quote></code>
C) <code>alert(message);</code>
D) <code>prompt(message);</code>
A) <code><msg>message</msg></code>
B) <code><quote>message</quote></code>
C) <code>alert(message);</code>
D) <code>prompt(message);</code>
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
13
What is the syntax for generating a dialog that prompts the user to answer yes or no to a question?
A) <code><prompt>message</prompt></code>
B) <code><ask>message</ask></code>
C) <code>alert(message);</code>
D) <code>confirm(message);</code>
A) <code><prompt>message</prompt></code>
B) <code><ask>message</ask></code>
C) <code>alert(message);</code>
D) <code>confirm(message);</code>
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
14
What is an <code>if</code> statement's condition?
A) A condition is a break in a web page that displays as a blank line.
B) A condition is a pause generated by a screen reader.
C) A condition is a question, surrounded by parentheses, that evaluates to true or false.
A) A condition is a break in a web page that displays as a blank line.
B) A condition is a pause generated by a screen reader.
C) A condition is a question, surrounded by parentheses, that evaluates to true or false.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
15
An <code>if</code> statement is an example of a:
A) declaration statement.
B) branching statement.
C) looping statement.
A) declaration statement.
B) branching statement.
C) looping statement.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
16
Which of the following statements is correct regarding an initialization statement?
A) It tells the browser engine that the program uses JavaScript for its language.
B) It links the web page's HTML code to its JavaScript code.
C) It is a combination of a variable declaration and an assignment.
A) It tells the browser engine that the program uses JavaScript for its language.
B) It links the web page's HTML code to its JavaScript code.
C) It is a combination of a variable declaration and an assignment.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
17
The <code>window</code> object's <code>screen</code> property holds information about the monitor that is being used.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
18
A named constant is a special variable whose value is fixed.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
19
To break/split a string in JavaScript, you should terminate the first part of the string with a closing quote, insert a(n) ______, and start the next line's continuation string with an opening quote.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
20
A(n) __________ is a pictorial representation of the logic flow of a computer program.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
21
Proper coding conventions suggest that when there are JavaScript statements inside of braces ({}), you should do which of the following?
A) Indent the statements inside the braces.
B) Position each statement's first character in the same column as the braces.
C) Separate the statements with commas, not semicolons.
A) Indent the statements inside the braces.
B) Position each statement's first character in the same column as the braces.
C) Separate the statements with commas, not semicolons.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
22
How can you test two strings to see if they are equal?
A) Call the equal method.
B) Call the equals method.
C) Use the = operator.
D) Use the == operator.
A) Call the equal method.
B) Call the equals method.
C) Use the = operator.
D) Use the == operator.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
23
Suppose you have a variable named character. What is the best way to assign a double quote (") to character?
A) character = "
B) character = '"';
C) character = "'";
D) character = "\'";
A) character = "
B) character = '"';
C) character = "'";
D) character = "\'";
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
24
The *:not(a) pseudo-class selector selects which of the following?
A) All noteworthy elements
B) All elements except for a elements (links)
C) Elements that are siblings of the current element
A) All noteworthy elements
B) All elements except for a elements (links)
C) Elements that are siblings of the current element
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
25
How can you round a price variable's value to the hundredths place (e.g., 204.89)?
A) Use the remainder operator, price % 2.
B) Use the division operator, price / 2.
C) Call the round method, price.round(2).
D) Call the toFixed method, price.toFixed(2).
A) Use the remainder operator, price % 2.
B) Use the division operator, price / 2.
C) Call the round method, price.round(2).
D) Call the toFixed method, price.toFixed(2).
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
26
The window object is known as the global object because all of its members are global.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
27
A dialog box is a control that supports verbal two-way communication between the user and the computer.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
28
A block statement (zero or more statements surrounded by braces) can be used anywhere a standard statement can be used.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
29
For the "if, else if, else" form of the if statement, if a condition is found to be true, that condition's block statement is executed. Then, all the other conditions are skipped, and control flows down to the statement below the entire if statement.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
30
The output element is for holding the result of a user's action.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck