CECS 189D EXAMINATION #1 SPRING 10 70 points MULTIPLE CHOICE 2 points for each correct answer Identify the choice that best answers the question on a Scantron 882 with a pencil #2. When you're on the campus to return the exam, you can buy the scantron at the coffee shop. Chapter 1 1. A web application is a type of a. client/server application c. JavaScript application b. database application d. server-side application 2. An HTTP response is sent from a. the web server to the application server b. the application server to the web server c. the client to the web server d. the web server to the client 3. When a client requests a dynamic web page, the XHTML is generated by a. the web server b. an application server c. a database server d. the web browser 4. JavaScript code is run by the a. database server b. application server c. web server d. web browser 5. Which of the following is NOT one of the four core web technologies? a. XHTML b. CSS c. DOM d. PHP 6. To load a web page into a web browser, you can a. type the URL of the web page into the browser s address bar b. type the just the filename of the web page into the browser s address bar c. type the domain name of the web page into the browser s address bar d. click the browser s Back button
7. To view the source code for a web page in the Firefox or IE browser, you can select the appropriate command from the Chapter 2 a. File menu b. Source menu c. View menu d. Page menu 8. 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 9. 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 10. 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 11. 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."); a. 22 is Tom's age. b. 22 is Tom's age. c. 22 \nis Tom's age. d. 22 \n is Tom's age. 12. 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; 13. 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" 14. 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 15. 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" 16. 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 17. 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 18. 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; 19. (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 ); 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; 20. (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? Chapter 3 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. 21. An error that doesn t cause an error but produces the wrong results is known as a a. runtime error b. user error c. logic error d. syntax error 22. In the Firefox browser without Firebug, you can display error messages by selecting the appropriate command from the a. File menu b. View menu
Chapter 6 c. Error menu d. Tools menu 23. If the prompt method displays a dialog box, and the user enters some text and clicks on the OK button, what does the prompt method return? a. a null value b. a Boolean value c. a numeric value d. a string value 24. For the following code, if the user clicks the Cancel button in the first dialog box that s displayed, a second dialog box is displayed that says... var firstname = prompt("please enter your first name:"); if ( firstname == null ) { alert("you must enter your first name."); else if (firstname == "") { alert("first name is required."); else { alert("thank you."); a. Please enter your first name: b. You must enter your first name. c. First name is required. d. Thank you. 25. What property of the Radio object is used to determine if a radio button is selected? a. the value property b. the checked property c. the selected property d. the radio property 26. For a Textarea object, what property do you use to get the text that has been entered into the text area? a. the value property b. the text property c. the name property. d. the string property. 27. 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; a. attached to the onload event of the global window object.
b. attached to the onload event of a control with an id of investment. c. attached to the onchange event of the global window object. d. attached to the onchange event of a control with an id of investment. 28. Assuming you have a radio button with an id of contact_via, which of the following statements selects that radio button? a. $("contact_via").selected = true; b. $("contact_via").checked = true; c. $("contact_via").value = true; d. $("contact_via").enabled = true; 29. How can you clear a check from a Checkbox object? Chapter 7 a. set its clear property to true b. set its checked property to false c. set its value property to an empty string d. call its blur method 30. 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 31. What method of the String object searches the string for an occurence of the specified search string? a. the charat method b. the search method c. the indexof method d. the substring method 32. Which of the following statements is NOT a valid way to create a date object named birthday? a. var birthday = "12/2/1978"; b. var birthday = new Date(); c. var birthday = new Date("12/2/1978"); d. var birthday = new Date(1978, 11, 2); 33. What method of the Date object gets the day of the month in local time? a. the getmonth method b. the getdate method c. the getday method d. the getdayofmonth method
34.What text does the following code display in the dialog box? var investment = "$100"; if (isnan(investment) investment <= 0) { alert("investment is not valid."); else { alert("investment: " + investment.tofixed(2)) a. Investment is not valid. b. Investment: $100 c. Investment: $100.00 d. Investment: 100.00 35. What is the value of salestax after the following code executes? var salestax = 53.937; salestax = parsefloat( salestax.tofixed(2) ); a. NaN b. 53.937 c. 53.94 d. 53.93