prep for Mid term
Assuming you have a radio button with an id of "contact_via", which of the following statements selects that radio button?
$("contact_via").checked=true
Which of the following is a valid selector for a class named menu?
.menu
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
Which of the following statements is false?
A JavaScript identifier can start with a number
Cross-browser compatibility is a serious development issue because Internet Explorer and the other browsers don't always interpret
HTML, CSS, and JavaScript the same way
A coding error that produces the wrong results when the application is run is known as a
Logic error
To make sure that the ECMAScript 5 features will work in older browsers, you can use
The shim.js file
var add = function( x, y ) { return ( x + y ); } alert( add (5, 3) );
accepts 2 parameters and returns 1 value.
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; } Assuming that there are no other problems and that you're using strict mode, what will happen when this code is executed?
an error will occur because salestax hasn't been declared
For the following code, an event handler named investment_change is var investment_change = function() { var years = parseInt( $("years").value ); alert("Years: " + years); } window.onload = function() { $("investment").onchange = investment_change; }
attached to the onchange event of a control with an id of "investment".
The following code var display_error = function(message) { alert("Error: " + message); }
creates a function and stores it in a variable named display_error
Now that HTML5 is used by all modern browsers, the HTML div element should be used primarily for grouping
elements for JavaScript and jQuery applications
When the statement that follows is executed, JavaScript var rate = parseFloat(document.getElementById("rate").value);
executes the getElementById method, gets the value property of the resulting object, and executes the parseFloat method on that value
The order of precedence for arithmetic expressions causes
multiplication operations
If you're using the Chrome browser and a JavaScript application stops running due to an error in the JavaScript code, you can identify the statement that caused the error by
pressing F12 and reviewing the code in the Sources panel
How can you clear a check from a Checkbox object?
set its checked property to false
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
When you develop a web page, you should use HTML to provide
the structure and content for the page
For a Textarea object, what property do you use to get the text that has been entered into the text area?
the value property
An HTTP response is sent from
the web server to the client
To load a web page from a local server into your web browser, you can
use the Open or Open File command in the File menu
Which of the following is a valid statement for declaring and initializing a variable named length to a starting value of 120?
var length = 120;
JavaScript code runs on the
web browser
var discountAmount; var orderTotal = 200; if (orderTotal > 200) { discountAmount = orderTotal * .3; } else if (orderTotal > 100) { discountAmount = orderTotal * .2; } else { discountAmount = orderTotal * .1; }
40.0
What does the code that follows do? $("email").firstChild.nodeValue = "Entry is invalid.";
Sets the text for the element with email as its id attribute
To remove the focus from a control, what method do you use?
the blur method
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."; }
1 years, and 1 months
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 * annualRate; }
1100
var totals = [141.95, 212.95, 411, 10.95]; totals[2] = 312.95; var totalsString = ""; for (var i = 0; i < totals.length; i++) { totalsString += totals[i] + "|"; }
141.95|212.95|312.95|10.95|
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; }
4
Which of the following is NOT one of the three testing phases of a JavaScript application?
DOM
When the statement that follows is executed, a message is displayed if the value in userEntry if (!isNaN(userEntry) || userEntry <= 0 ) { alert ("Message"); }
Is a number or the value in userEntry is less than or equal to zero
var add = function( x, y ) { return ( x + y ); } alert( add (5, 3) );
The alert method in this example displays a dialog box with a value of "8".
Within a CSS rule set, a rule includes
a property and a value
Sometimes, validating the HTML code for a web page will help you debug an application, because
a trivial HTML error can cause other types of errors
When a client requests a dynamic web page, the HTML is generated by
an application server
Three of the common CSS selectors select
by element type, id attribute, and class attribute
The class attribute
can be used by CSS to apply the same formatting to more than one HTML element
The easiest way to 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 Aptana to edit an HTML file, the easiest way to test it is to
click on the Run button in Aptana's toolbar
To view the changes that have been made to the DOM for a page by the JavaScript, you can
display the HTML for the page in Chrome's Element panel
After the statements that follow are executed, var firstName = "Ray", lastName = "Harris"; var fullName = lastName; fullName += ", "; fullName += firstName;
fullName="Harris, Ray"
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
To display data in a span element, you can use the firstChild property to get a pointer to the Text node. Then, what property of the Text node can you use to set the value that's displayed in the span element?
nodeValue
After the statement that follows is executed, rateText represents var rateText = document.getElementById("rate");
the HTML element with "rate" as its id attribute
What event occurs when the user selects a new item from a select list?
the change event
What property of the Radio object is used to determine if a radio button is selected?
the checked property
To load a web page into a web browser, you can
type the URL of the web page into the browser's address bar