Please all answers for review mines. thanks JavaScript and DOM Scripting Chapter
ID: 3638646 • Letter: P
Question
Please all answers for review mines. thanksJavaScript and DOM Scripting
Chapter 2: How to code a JavaScript application
COMPLETION
1. To start a/an __________________________ comment, you code //.
2. If you split a JavaScript statement over two lines in the wrong place, JavaScript will put a/an ______________________ at the end of the first line, and that will sometimes cause an error.
3. An identifier in JavaScript cannot contain ___________________ words.
4. If you want to store a true or false value in a variable, you use the __________________ data type.
5. You use the _____________ escape sequence to start a new line in a string variable.
6. If an arithmetic expression isn’t evaluated the way you want it to be due to the order of precedence, you can override that order by using ____________________.
7. To declare a variable, you code the keyword _____________________ followed by the name of the variable.
8. In a simple assignment statement, you use the _____________________ operator.
9. In the code that follows, document is a/an ____________________________.
document.getElementById("emailAddress");
10. In the code that follows, getElementById is a/an ____________________________.
document.getElementById("emailAddress");
11. The code that follows is an example of __________________________.
document.getElementById("emailAddress").value.toLowerCase();
12. When you declare a variable and assign a string expression to it, a/an _______________________ is created.
13. In a web browser, the ____________________ object is the object that’s always available to JavaScript so you don’t have to code its name when you call one of its methods.
14. If possible, the parseInt method converts the string that’s passed to it to a/an _____________________________.
15. The toFixed method of a number object returns a/an __________________________ that contains the value of the object rounded to the number of decimal places in the parameter.
16. After the code that follows is executed, okFlag contains a value of ___________________.
var okFlag = !isNaN("12.345");
17. The condition for a while loop is tested ______________ the statements in the loop are executed.
18. To create a function, you code the keyword function followed by a set of parentheses that contains any parameters, followed by a set of ______________________ that contains the statements that are to be executed when the function is called.
19. When you call a function that returns a value, you usually ________________ the result of the function to a variable.
20. To execute the code that’s stored in a function when the user clicks on a button, you create an event handler for the __________________ event of the button.
21. You can use the event handler for the __________________ event of the web page to assign event handlers to the click event of a button.
MULTIPLE CHOICE
1. When you use a text editor like Notepad++, it provides color coding and auto completion
a. for the JavaScript in a file
b. for both the JavaScript and XHTML in a file
c. for the JavaScript, XHTML, and CSS in a file
d. for JavaScript, XHTML, and CSS files based on the file extension
2. If there’s an error in your JavaScript code when you’re using Firefox, you can view the error message in the Error Console by selection the appropriate command from the
a. File menu c. Tools menu
b. View menu d. Error menu
3. JavaScript will automatically attempt to insert a semicolon at the end of a line when you split a statement across multiple lines
a. after the = operator c. after the return statement
b. after an opening brace d. after the + operator
4. A JavaScript identifier
a. isn’t case-sensitive
b. can’t start with a $ sign
c. can’t start with a number
d. can’t be more than 128 characters long
5. Assume userName equals “Tom” and userAge equals 22. What is displayed in a dialog box when the following statement is executed?
alert(userAge + " is " + userName + "'s age.");
a. 22 is Tom's age.
b. 22
is Tom's age.
c. 22 is Tom's age.
d. 22
is Tom's age.
6. The order of precedence for arithmetic expressions causes
a. multiplication operations to be performed before addition operations
b. division operations to be performed after subtraction operations
c. increment operations to be performed after modulus operations
d. addition operations to be performed before subtraction operations
7. Which of the following is a valid statement for declaring and initializing a variable named length to a starting value of 120?
a. length = 120; c. var length = 120;
b. int length = 120; d. num length = 120;
8. After the statements that follow are executed,
var firstName = "Ray", lastName = "Harris";
var fullName = lastName;
fullName += ", ";
fullName += firstName;
a. firstName is "Harris" c. fullName is "Ray"
b. firstname is "Ray Harris" d. fullName is "Harris, Ray"
9. After the statement that follows is executed, rateText contains
var rateText = document.getElementById("rate");
a. the string that was entered in the XHTML element with “rate” as its id
b. a reference to the XHTML element with “rate” as its id
c. the value that was entered in the XHTML element with “rate” as its id
d. the XHTML element with “rate” as its id
10. After the statements that follow are executed, guest contains
var guest = "Ray Harris";
var quest = guest.substr(0,3).toUpperCase();
a. "Ray Harris" c. "Ray"
b. "RAY Harris" d. "RAY"
11. When the statement that follows is executed, JavaScript
var rate = parseFloat(document.getElementById("rate").value);
a. executes the getElementById method, executes the value method of the resulting object, and executes the parseFloat method on that value
b. executes the getElementById method, gets the value property of the resulting object, and executes the parseFloat method on that value
c. executes the parseFloat method, executes the getElementById method, and executes the value method of the resulting object
d. executes the parseFloat method, executes the getElementById method, and gets the value property of the resulting object
12. When the statement that follows is executed, the message is displayed if the value in userEntry
if ( !isNaN(userEntry) || userEntry <= 0 ) {
alert ("Message");
}
a. isn’t a number or the value in userEntry is less than or equal to zero
b. isn’t a number and the value in userEntry is less than or equal to zero
c. is a number or the value in userEntry is less than or equal to zero
d. is a number and the value in userEntry is less than or equal to zero
13. After the if statement that follows is executed, what will the value of discountAmount be?
var discountAmount;
var orderTotal = 200;
if (orderTotal > 200) {
discountAmount = orderTotal * .3;
} else if (orderTotal > 100) {
discountAmount = orderTotal * .2;
} else {
discountAmount = orderTotal * .1;
}
a. 0.0 c. 40.0
b. 20.0 d. 60.0
14. If totalMonths has a string value of “13”, what does the if statement that follows display?
var years = parseInt ( totalMonths / 12 );
var months = totalMonths % 12;
if ( years == 0 ) {
alert ( months + " months.");
} else if ( months == 0 ) {
alert ( years + " years");
} else {
alert ( years + " years, and " + months + " months.";
}
a. 1 years, and 1 months
b. 1 year, and 1 month
c. 1 years
d. 1 year
15. How many times will the while loop that follows be executed?
var months = 5;
var i = 1;
while (i < months) {
futureValue = futureValue * (1 + monthlyInterestRate);
i = i+1;
}
a. 0 c. 5
b. 4 d. 6
16. What will futureValue contain after the for loop has been executed one time?
var years = 10;
var annualRate = 10;
var futureValue = 1000;
annualRate = annualRate / 100;
for ( i = 1; i <= years; i++ ) {
futureValue = futureValue * (1 + annualRate);
}
a. 1000 c. 11000
b. 1100 d. 1010
Code example 2-1
var calculateTax = function ( subtotal, taxRate ) {
var tax = subtotal * taxRate;
tax = parseFloat( tax.toFixed(2) );
return tax;
}
17. (Refer to code example 2-1) Which call statement will get the right result if the subtotal is $1000, the tax rate is 8%, and the value that’s returned by the function should be stored in a numeric variable?
a. var tax = calculateTax( $1000, 8% );
b. var tax = calculateTax( 1000, 8 );
c. var tax = calculateTax( 1000, .08 );
d. calculateTax( subtotal, taxRate );
18. (Refer to code example 2-1) If you pass the values 100 and .00224 to the calculateTax function, what value will be returned?
a. .224 c. .22
b. 2.24 d. .23
Code example 2-2
var $ = function ( id ) {
return document.getElementById( id );
}
var display_name_click = function () {
$("name_text_box").value = "Mike";
}
window.onload = function () {
$("display_button").onclick = display_name_click;
}
19. (Refer to code example 2-2.) Assuming the web page for this script has a text field with an id attribute of name_text_box and a button with an id attribute of display_button, what will happen when the user clicks the button?
a. The application will display “Mike” in a dialog box.
b. The application will display “Mike” in the text field named name_text_box.
c. The application will display “Mike” in the button named display_button.
d. The application won’t display anything.
20. (Refer to code example 2-2.) What does the code in the third function do?
a. Assign an event handler named display_button to the click event of a button.
b. Assign an event handler named display_name_click to the click event of a button.
c. Create an event handler named display_button.
d. Create a function named display_button.
21. (Refer to code example 2-2.) When will the code for the third function run?
a. When the name is displayed.
b. When the user clicks on the button.
c. As the page is loaded in the browser.
d. After the page is loaded in the browserr.
Explanation / Answer
1/.one line 2. mcq. 1 a 2a 3d 4a 5b 6c 7b
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.