Question: JavaScript Programming 1. 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
JavaScript Programming
1. 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 |
2. The following code
var display_error = function(message) {
alert("Error: " + message);
}
| a. | creates a function named display_error. |
| b. | creates a function and stores it in a variable named display_error. |
| c. | creates a function named message. |
| d. | calls a function named message. |
Code example 4-1
var add = function( x, y ) {
return ( x + y );
}
alert( add (5, 3) );
3. (Refer to code example 4-1) The function in this example
| a. | accepts 2 parameters and returns 2 values. |
| b. | accepts 2 parameters and returns 1 value. |
| c. | accepts 2 parameters and does not return a value. |
| d. | does not accept a parameter and returns 1 value. |
4. (Refer to code example 4-1) The alert method in this example
| a. | displays a dialog box with a value of 8. |
| b. | displays a dialog box with a value of 5, 3. |
| c. | displays a dialog box with a value of x + y. |
| d. | does not display a dialog box. |
4. Which of the following is NOT one of the three testing phases of a JavaScript application?
| a. | Trying to make the application fail |
| b. | Using the developer tools to check the DOM |
| c. | Testing the application with valid data |
| d. | Testing the application with invalid data |
5. The code that follows has a bug in it because the second use of the variable named salesTax is spelled with all lowercase letters (salestax).
var calculateTax = function(subtotal,taxRate) {
var salesTax = subtotal * taxRate;
salestax = parseFloat(salesTax.toFixed(2));
return salesTax;
}
6. Assuming that there are no other problems and that youre using strict mode, what will happen when this code is executed?
| a. | salesTax will contain the right value, but it wont be rounded |
| b. | an error will occur because salestax hasnt been declared |
| c. | salestax will contain the rounded sales tax value |
| d. | salesTax will contain null when it is returned |
7. When you test an application with Chromes developer tools and a breakpoint is reached, you can view the current data by
| a. | moving the mouse pointer over the name of a variable in the Sources panel |
| b. | clicking in the bar to the left of a statement that uses an arithmetic expression |
| c. | hovering the mouse pointer over a variable name in the Elements panel |
| d. | looking up the variable in the names table in the Console panel |
8. If a numerical operation returns a number greater than the largest possible JavaScript value, it returns
| a. | NaN |
| b. | -NaN |
| c. | Infinity |
| d. | -Infinity |
9. What method of the Number object returns a string with the number rounded to the specified number of decimal places?
| a. | the toString method |
| b. | the round method |
| c. | the toPrecision method |
| d. | the toFixed method |
10. What text does the following code display in a dialog box?
alert("The file is in \"C:\\My Documents\"");
| a. | The file is in C:\My Documents |
| b. | The file is in "C:\My Documents" |
| c. | The file is in C:\\My Documents\ |
| d. | The file is in "C:\\My Documents\" |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
