Client-Side Programming Mid-Term Exam Study Guide
What is the value of the constant named result after the following code executes? const X = 6; const Y = 4; const Z = 2; const result = X + Y / Z * X;
18
What is the value of the constant named result after the following code executes? const X = 6; const Y = 4; const Z = 2; const result = ( X + Y ) / Z * X;
30
How many times will the while loop that follows be executed? const months = 5; let i = 1; while (i < months) { console.log(i); i++; }
4
Which of the following statements about functions is NOT true?
Function declarations cannot return a value.
Most modern browsers support recent ECMAScript specifications. Which of the following isn't considered a modern browser?
Internet Explorer
When using Chrome's developer tools, which panel can you use to view the HTML and CSS for a page?
The Elements panel
If you are NOT using strict mode, what happens if you declare a variable named firstName and later refered to it as firstname?
The JavaScript engine creates a new global variable named firstname
What is displayed in the alert dialog box after the following code is executed? const scores = [70, 20, 35, 15]; scores[scores.length] = 40; alert("The scores array: " + scores);
The scores array: 70, 20, 35, 15, 40
When a client requests a static web page, the HTML is
accessed from the web server
The condition for a while loop is tested
before the statements in the loop are executed
Which of the following is NOT part of an HTTP URL:
node
To write a string to a document, use
the write() method
To interact with a web server, the client for a web application typically uses a
web browser
What is the value of the constant named result after the following code executes? const X = 15; const Y = 3; const Z = 2; const result = X % Y * Z;
0
What does the following code display on the console? const pets = ["Dog", "Cat", "Bird"]; for(let i in pets) { console.log(i + ". " + pets[i]); }
0. Dog 1. Cat 2. Bird
What is the value of the message variable after the following code is executed? const totals = [141.95, 212.95, 411, 10.95]; totals[2] = 312.95; let message = ""; for (let total of totals) { message += total + "|"; }
141.95 | 212.95 | 312.95 | 10.95|
Assume userName equals "Tom" and userAge equals 22. What is displayed in a dialog box when the following statement is executed? alert(userAge + "\nis " + userName + "'s age.");
22 is Tom's age.
What is the value of the num_colors variable? var colors = ["red","blue","orange","yellow","green","brown","purple"]; num_colors = colors.length;
7
After the following statements execute, what's the value of the constant named message? const descr = "Hammer"; const price = 12.99; const message = `A ${descr} costs ${price}.`;
A hammer costs 12.99.
Which version of EcmaScript is also known as ES6?
ES2015
What is wrong with the following JavaScript identifier? $the_value_1st_user_enters_for_a_name
Nothing is wrong with this identifier
To display string or numeric data in a dialog box, use the
alert() method
When you use the relational operators, you can compare
all of the above
Which type of selector would you use to refer to a specific HTML element?
an ID selector
The quickest way to re-run a web page that's already in your browser after you've made changes to the code for the page is to
click on the Reload or Refresh button
If you're using the Chrome browser and a JavaScript application stops running due to an error in the JavaScript code, you can view the statement that caused the error by first pressing F12. Then, you can
click on the link in the Console panel and review the code in the Sources panel
Which of the following is a valid arrow function for a function named getUserAge() that accepts one parameter?
const getUserAge = user => {};
To trace the execution of a JavaScript application so you can view the results when the application ends, you would
insert console.log() method calls at key points in the code
Which of the following is a valid statement for declaring and initializing a variable named length to a starting value of 120?
let length = 120;
A coding error that produces the wrong results when the application is run is known as a
logic error
Which of the following is NOT one of the three testing phases of a JavaScript application?
misspelling keywords
In a web browser, which object is always available to JavaScript so you don't have to code its name when you call its methods?
the window object
What value is returned by the following expression? !isNaN(12.345)
true
Suppose that a JavaScript application on the Internet consists of an HTML file, a CSS file, and a JavaScript file. To run the application, you can
type the URL of the HTML file into the browser's address bar
Given the following $() function, which of the following attaches an event handler to the mouseover event for a textbox with an id of "username"? const $ = selector => document.querySelector(selector);
$("#username").addEventListener("mouseover", () => { alert("Hi " + $("#username").value); });
Which of the following will test whether a Boolean variable named isValid is true?
(isValid)
Consider the following code: const tax = .07; const getCost = (itemCost, numItems) => { const subtotal = itemCost * numItems; const tax = 0.06; const total = subtotal + subtotal * tax; return total; } const totalCost = getCost(25.00, 3); alert("Your cost is $" + totalCost.toFixed(2) + " including a tax of " + tax.toFixed(2)); What is the value of the global constant named tax?
.07
Which of the following is a valid CSS selector for a class named menu?
.menu
What message does the code that follows display? const totalMonths = 13; const years = parseInt(totalMonths / 12); const months = totalMonths % 12; if ( years == 0 ) { alert ( months + " months."); } else if ( months == 0 ) { alert ( years + " years"); } else { alert ( years + " years, and " + months + " months."); }
1 years, and 1 months
What will futureValue contain after the for loop has been executed one time? const years = 10; let annualRate = 10; annualRate = annualRate / 100; let futureValue = 1000; for (i = 1; i <= years; i++) { futureValue += futureValue * annualRate; }
1100
What is the value of the variable named counter after the code that follows is executed? const percent = 0.54; const isValid = true; let counter = 1; if (percent > 0.50 && isValid) { counter += 2; if (isValid) { counter++; } else if (percent >= 0.50) { counter += 3; } }
4
After the code that follows is executed, what is the value of discountAmount? let discountAmount; const orderTotal = 200; if (orderTotal > 200) { discountAmount = orderTotal * .3; } else if (orderTotal > 100) { discountAmount = orderTotal * .2; } else { discountAmount = orderTotal * .1; }
40.0
What is the value of the variable named myNum after the statements that follow are executed? let myNum = 14; let yourNum = 4; myNum++; yourNum-- myNum = myNum * yourNum;
45
After the code that follows is executed, the variable named userEntry will contain let userEntry = 461.95; userEntry = parseInt(userEntry);
461
What is the value of entry after the following statements are executed? let entry = 9, number = 3; if (entry > 9 || entry/number == 3) { entry--; } else if (entry == 9) { entry++; } else { entry = 3; }
8
Which of the following is NOT a relational operator?
=
Which attribute uniquely identifies an HTML element? .red { color: red; }
All elements with the class named red
Assuming that there are no other problems and that you're using strict mode, what will happen when the following code is executed?
An error will occur because salestax hasn't been declared.
Which of the following correctly identifies three of the primitive data types provided by JavaScript?
Boolean, numeric, string
In the following statement, which expression is evaluated first? const truth = !A || B && (C || D)
C || D
Consider the following code example: const getResult = () => { const num1 = 54.95; const num2 = .1; const result = parseFloat(prompt(`What is ${num1} * ${num2}?`)); if (result != (num1 * num2)) { alert("Incorrect"); } else { alert("Correct!"); } }; Which of the following would fix the error in the code example?
Change the condition of the if statement to: if (result != (num1 * num2).toFixed(3))
After the statements that follow execute, what's the value of the variable named fullName? const firstName = "Ray", lastName = "Harris"; let fullName = lastName; fullName += ", "; fullName += firstName;
Harris, Ray
Which attribute uniquely identifies an HTML element?
ID
Consider the following code: const $ = selector => document.querySelector(selector); document.addEventListener("DOMContentLoaded", () => { $("#ship_button").addEventListener("click", evt => { evt.preventDefault(); alert(evt.currentTarget.value); }); alert("Welcome to the Calculate Cost page"); }); What happens as soon as the page that contains the code loads?
It displays a dialog box that displays "Welcome to the Calculate Cost page".
Consider the following code: const $ = selector => document.querySelector(selector); document.addEventListener("DOMContentLoaded", () => { $("#ship_button").addEventListener("click", evt => { evt.preventDefault(); alert(evt.currentTarget.value); }); alert("Welcome to the Calculate Cost page"); }); Assuming the HTML element with the id of "ship_button" is a submit button, what happens if the user clicks on it?
It does not submit the form and displays a dialog box that displays the text of the button.
ECMAScript is a specification that provides a standard for
JavaScript
What is displayed by the alert dialog box after the following code executes? const name = "Donny,Duck"; const index = name.indexOf(","); const lastName = name.substr(index + 1, 3); alert("Last name: " + lastName);
Last name: Duc
Which HTML element typically contains the main content of a web page?
Main
If the current date is Monday, February 26, 2017, what will be displayed by the alert dialog box after the following code executes? const today = new Date(); alert(today.toDateString());
Mon Feb 26 2017
What does the following code do? document.querySelector("#amount").focus();
Moves the focus to the HTML element with an id of "amount"
Consider the following code example: let myAge = prompt("How old are you?"); myAge = parseInt(myAge); const newAge = 18 - myAge; alert("You will be eligible to vote in " + newAge + " years"); What type of data is stored in myAge after the first line is executed?
String data
Which of the following is NOT true about using Chrome's developer tools to test an application?
The Sources panel displays a list of all runtime errors in the order they appear in your code.
Consider the following code: const tax = .07; const getCost = (itemCost, numItems) => { const subtotal = itemCost * numItems; const tax = 0.06; const total = subtotal + subtotal * tax; return total; } const totalCost = getCost(25.00, 3); alert("Your cost is $" + totalCost.toFixed(2) + " including a tax of " + tax.toFixed(2)); This code contains an error. Identify the error.
The alert dialog box will display an incorrect value for the tax rate.
Consider the following code: let name = prompt("Enter a name"); while (name.length > 12) { name = prompt("Too long. Enter a name with fewer than 12 characters."); } alert("The name is " + name.toUpperCase()); What does the code display if the user enters Edgar A. Poe at the first prompt?
The name to be printed is EDGAR A. POE
Consider the following code example: const getResult = () => { const num1 = 54.95; const num2 = .1; const result = parseFloat(prompt(`What is ${num1} * ${num2}?`)); if (result != (num1 * num2)) { alert("Incorrect"); } else { alert("Correct!"); } }; Why would "Incorrect" be displayed if the user entered 5.495 when prompted by this code?
The results of arithmetic calculations that use floating-point numbers are imprecise.
Consider the following code: let name = prompt("Enter a name"); while (name.length > 12) { name = prompt("Too long. Enter a name with fewer than 12 characters."); } alert("The name is " name.toUpperCase()); What does the code display if the user enters Willy Shakespeare at the first prompt?
Too long. Enter a name with fewer than 12 characters.
If you do not want the user to be allowed to enter data into a text box,
Use the disabled property to gray out the textbox
Consider the following code example: let myAge = prompt("How old are you?"); myAge = parseInt(myAge); const newAge = 18 - myAge;alert("You will be eligible to vote in " + newAge + " years"); What would be returned if the user entered 14.78 at the prompt?
You will be eligible to vote in 4 years
Consider the following code example: let myAge = prompt("How old are you?"); myAge = parseInt(myAge); const newAge = 18 - myAge; alert("You will be eligible to vote in " + newAge + " years"); What would be returned if the user entered "fifteen" at the prompt?
You will be eligible to vote in NaN years
After the code that follows executes, the alert dialog box will display const userCost = 29.94999; alert("Your cost is $" + parseFloat(userCost.toFixed(2)));
Your cost is $29.95
Within a CSS style rule, a property declaration includes
a property and a value
To include JavaScript from a file in a web page, you can code
a script element at the end of the body element of the HTML for a page
To make a website available to other computers over a network, the website is stored on
a web server
Consider the following code: function add(x, y) { return x + y; } alert(add(5, 3)); The function in this example
accepts 2 parameters and returns 1 value
After the statement that follows is executed, images represents ' const images = document.querySelectorAll("img");
all HTML img elements
Which of the following statements is/are true? Whitespace
all of the above are true
When a client requests a dynamic web page, the HTML is generated by
an application server
You can use a link element in an HTML document to provide
an external style sheet
A value assigned to a variable or a constant can be
any of the above
Syntax errors
are caught by the JavaScript engine as a page is loaded into the web browser.
The class attribute
can be used by CSS to apply the same formatting to more than one HTML element
Which of the following statements is false? A JavaScript identifier
can start with a number
Which of the following constants stores a Boolean value? const choice = true; const again = "false"; const result = 10;
choice
Consider the following code: function add(x, y) { return x + y; } alert(add(5, 3)); Which of the following statements performs the same task as the function in this example?
const add = (x, y) => x + y;
The following code const displayError = message => { alert("Error: " + message); };
creates a function and stores it in a constant named displayError
Commenting out a portion of code is typically used to
disable a portion of code for testing purposes
Which HTML element can be used to group elements when none of the semantic elements apply?
div
Which of the following loops always executes its block of code at least once?
do-while loop
Which of the following will display the value of birthday in the document, formatted as Wed Feb 08 2017? const birthday = new Date();
document.write(birthday.toDateString());
Suppose that a JavaScript application that's on your computer consists of an HTML file, a CSS file, and a JavaScript file. To run the application, you can
find the HTML file in your file system and double-click on it
When you debug an application, you
fix the bugs that have been identified
Which of the following is a valid function declaration for a function named getUserAge() that accepts one parameter?
function getUserAge(user) {}
Consider the following code: const tax = .07; const getCost = (itemCost, numItems) = { const subtotal = itemCost * numItems; const tax = 0.06; const total = subtotal + subtotal * tax; return total; } const totalCost = getCost(25.00, 3); alert("Your cost is $" + totalCost.toFixed(2) + " including a tax of " + tax.toFixed(2)); Which constant stores the arrow function?
getCost
Which statements are equivalent to the if statements that follow? if (pay >= 500) { tax_rate = 0.3; } if (pay >= 300 && pay < 500) { tax_rate = 0.2; } if (pay >= 100 && pay < 300) { tax_rate = 0.1; }
if (pay >= 500) { tax_rate = 0.3; } else if (pay >= 300) { tax_rate = 0.2; } else if (pay >= 100) { tax_rate = 0.1;}
When the code that follows is executed, a message is displayed if the value the user enters const userEntry = prompt("Enter cost:"); if (isNaN(userEntry) || userEntry > 500 ) { alert ("Message"); }
is not a number OR the value in userEntry is more than 500
Because window is the global object of JavaScript,
it is not necessary to code the object name before the method name
In the code that follows, querySelector() is a/an document.querySelector("#emailAddress");
method
When you test an application with Chrome's developer tools and a breakpoint is reached, you can view the current data by
moving the mouse pointer over the name of a variable in the Sources panel
The order of precedence for arithmetic expressions causes
multiplication operations to be performed before addition operations
The equal to (==) and not equal to (!=) operators should
not be used to compare floating-point numbers
In the code that follows, document is a/an document.querySelector("#emailAddress");
object
In the code that follows, window is a/an window.prompt("Enter your name");
object
To allow a user to enter a value into a dialog box, use the
prompt() method
Data or attributes that are associated with an object are its
properties
What sequence of components does an HTTP URL consist of before the filename?
protocol, domain name, path
Which of the following types of errors will cause an application to stop executing?
runtime error
After the statement that follows is executed, rateText represents const rateText = document.querySelector("#rate");
the HTML element with "rate" as its id attribute
JavaScript code is run by
the JavaScript engine in the web browser
When you test an application with Chrome's developer tools and a breakpoint is reached, you can click
the Step Into button to execute the current statement and move to the next statement
If you use a short-circuit operator to combine two expressions
the second expression is evaluated only if it can affect the result
When you develop a web page, you use an HTML file to provide
the structure and content for the page
To get the contents of a Textbox object, you use
the value property
An HTTP response is sent from
the web server to the client
To avoid potential errors caused by using variables or constants that are not properly declared, you should
use strict mode
When declaring a variable or constant, which keyword can lead to hard-to-find bugs because it causes the variable or constant to be initialized to undefined when it's hoisted?
var