Click here to load reader
Upload
hoangque
View
213
Download
0
Embed Size (px)
Citation preview
Full file at http://TestbankCollege.eu/Test-Bank-New-Perspectives-on-JavaScript-and-AJAX-Comprehensive-2nd-Edition-Carey
Tutorial 2: Working with Operators and Expressions
TRUE/FALSE
1. You can add a dynamic effect to a Web site using ontime processing.
ANS: F PTS: 1 REF: JVS 54
2. You can not insert values into a Web form’s fields.
ANS: F PTS: 1 REF: JVS 55
3. An event is an action that occurs within a Web browser or Web document.
ANS: T PTS: 1 REF: JVS 56
4. In the code <body onload = "myFunction()" ...>, myFunction() is executed when the page loads.
ANS: T PTS: 1 REF: JVS 57
5. Across the different web browsers and their versions, there is support for the same set of events.
ANS: F PTS: 1 REF: JVS 58
6. The time object is used in JavaScript to work with dates.
ANS: F PTS: 1 REF: JVS 59
7. You use the thisDate() function to get the current date and time.
ANS: F PTS: 1 REF: JVS 59
8. The getDate() method returns the specific month for a particular date.
ANS: F PTS: 1 REF: JVS 61
9. To get a two digit year, you use the getYear() method.
ANS: T PTS: 1 REF: JVS 61
10. JavaScript only allows the minutes and seconds to be retrieved from a date.
ANS: F PTS: 1 REF: JVS 61
11. JavaScript does not support daylight savings time.
ANS: T PTS: 1 REF: JVS 63
12. When writing your own function, you begin by using the word "method".
Full file at http://TestbankCollege.eu/Test-Bank-New-Perspectives-on-JavaScript-and-AJAX-Comprehensive-2nd-Edition-Carey
ANS: F PTS: 1 REF: JVS 63
13. Binary operators work on only one operand.
ANS: F PTS: 1 REF: JVS 67
14. You use the ++ operator to increment a variable in JavaScript.
ANS: T PTS: 1 REF: JVS 67
15. To avoid misunderstanding the actions of a decrement operator, read the action of the operator from right to left.
ANS: F PTS: 1 REF: JVS 68
16. If you insert a space between the two symbols of the assignment operator, JavaScript will report a syntax error.
ANS: T PTS: 1 REF: JVS 68
17. JavaScript measures time in terms of days.
ANS: F PTS: 1 REF: JVS 70
18. To use the round method, you type "math.round()".
ANS: F PTS: 1 REF: JVS 73
19. The Math.random() method returns a value between 0 and 1.
ANS: T PTS: 1 REF: JVS 74
20. The value.toFixed(n) method can be used to control the number of digits displayed by the browser.
ANS: T PTS: 1 REF: JVS 80
MODIFIED TRUE/FALSE
1. One way of inserting an event handler is to add it as an attribute of the element in the Web document. _________________________
ANS: T PTS: 1 REF: JVS 56
2. The onclick event handler handles when the mouse button has been pressed. _________________________
ANS: F, onmousedown
PTS: 1 REF: JVS 57
Full file at http://TestbankCollege.eu/Test-Bank-New-Perspectives-on-JavaScript-and-AJAX-Comprehensive-2nd-Edition-Carey
3. Another way to run a JavaScript command in response to an event is to treat it as a hypertext form. _________________________
ANS: F, link
PTS: 1 REF: JVS 58
4. To create a date object, you use new Time(). _________________________
ANS: F, new Date()
PTS: 1 REF: JVS 59
5. The time methods can be used to retrieve information from a date object. _________________________
ANS: F, date
PTS: 1 REF: JVS 60
6. The method to get the current hour from a date object is DateObject.getTimeHour(). _________________________
ANS: FDateObject.getHours()
PTS: 1 REF: JVS 61
7. The getTime() method retrieves the time value as expressed in milliseconds. _________________________
ANS: T PTS: 1 REF: JVS 62
8. The operators shown in the figure above are binary operators. _________________________
ANS: F, unary
Full file at http://TestbankCollege.eu/Test-Bank-New-Perspectives-on-JavaScript-and-AJAX-Comprehensive-2nd-Edition-Carey
PTS: 1 REF: JVS 68
9. The -- operator in the figure above is used to decrement variables. _________________________
ANS: T PTS: 1 REF: JVS 68
10. To make a function available to other pages, you should place the function in an external file. _________________________
ANS: T PTS: 1 REF: JVS 64
11. The figure above shows an example of a JavaScript object. _________________________
ANS: F, function
PTS: 1 REF: JVS 69
12. The portion of JavaScript code pointed at in the figure above calculates the number of seconds in a day. _________________________
ANS: F, milliseconds
PTS: 1 REF: JVS 70
13. The && is a(n) comparison operator. _________________________
ANS: F, logical
PTS: 1 REF: JVS 84
14. To cancel a time-delayed command called timeOne, you would use timeOne.clearTimeout(). _________________________
Full file at http://TestbankCollege.eu/Test-Bank-New-Perspectives-on-JavaScript-and-AJAX-Comprehensive-2nd-Edition-Carey
ANS: F, clearTimeout(timeOne)
PTS: 1 REF: JVS 88
15. In the following JavaScript code:
setTimeout("addThree()",50); setTimeout("showDate()",50);
the functions execute almost simultaneously. _________________________
ANS: T PTS: 1 REF: JVS 89
MULTIPLE CHOICE
1. In document.Contact.Name.value, the name of the form must be ____.a. Contact c. documentb. Name d. value
ANS: A PTS: 1 REF: JVS 55
2. A(n) ____ is a statement that tells browsers what code to run in response to the specified event.a. event script c. unary operatorb. event handler d. element attribute
ANS: B PTS: 1 REF: JVS 56
3. The ____ event handler runs when the browser has completed unloading the document.a. onload c. onerrorb. onremove d. onunload
ANS: D PTS: 1 REF: JVS 57
4. The ____ event handler tests whether or not a user has pressed and released a button on the keyboard.a. onquit c. onkeydownb. onclick d. onkeypress
ANS: D PTS: 1 REF: JVS 57
5. If a user clicks an item on a page, which event(s) may occur?a. ondblclick c. a onlyb. onclick d. either a or b
ANS: D PTS: 1 REF: JVS 57
6. The ____ event handler runs when a user has entered a text input field.a. onload c. onfocusb. onchange d. onblur
ANS: C PTS: 1 REF: JVS 57
Full file at http://TestbankCollege.eu/Test-Bank-New-Perspectives-on-JavaScript-and-AJAX-Comprehensive-2nd-Edition-Carey
7. To add code that runs when content of an input field has been modified, you use the ____ event handler.a. onload c. onfocusb. onchange d. onblur
ANS: B PTS: 1 REF: JVS 57
8. To have the function verify() execute when a person leaves the Name input field, you must use the ____ event handler.a. onload c. onfocusb. onchange d. onblur
ANS: D PTS: 1 REF: JVS 57
9. To give buttons an action on a form, you can use the ____ event.a. onblur c. onkeypressb. onclick d. onchange
ANS: B PTS: 1 REF: JVS 56
10. Which of the following is not a Window event?a. onresize c. onscrollb. onselect d. onmove
ANS: B PTS: 1 REF: JVS 57
11. Which of the following is not a mouse event?a. onmousedown c. onmouseclickb. onmouseup d. onmouseout
ANS: C PTS: 1 REF: JVS 57
12. Which of the following is not a keyboard event?a. onkeyout c. onkeypressb. onkeydown d. none of the above
ANS: A PTS: 1 REF: JVS 57
13. Older web browsers used ____ links to run JavaScript commands.a. paragraph c. hypertextb. image d. source
ANS: C PTS: 1 REF: JVS 58
14. A function includes its ____, which are values used by the function.a. terms c. idsb. parameters d. names
ANS: B PTS: 1 REF: JVS 63
15. ____ is the general syntax for using anchor tags to run JavaScript.a. <a alt = "javascript:script">content</a> c. <a href = "javascript:script">content</a>b. <a href = "script">content</a> d. <a src = "javascript:script">content</a>
Full file at http://TestbankCollege.eu/Test-Bank-New-Perspectives-on-JavaScript-and-AJAX-Comprehensive-2nd-Edition-Carey
ANS: C PTS: 1 REF: JVS 58
16. To create a date object using the current date and store it in myDate, you enter ____.a. myDate = new Date();b. myDate = new Time();c. myDate = new Time(2011, 1, 24, 14, 35, 5);d. myDate = new Date(2011, 1, 24, 14, 35, 5);
ANS: A PTS: 1 REF: JVS 59
17. January is indicated by the number ____ in JavaScript.a. 0 c. 4b. 1 d. 10
ANS: A PTS: 1 REF: JVS 59
18. Dates are numeric values measured in ____.a. milliseconds c. microsecondsb. nanoseconds d. picoseconds
ANS: A PTS: 1 REF: JVS 60
19. The ____ method always returns the year in four digit format.a. getYear(); c. getDate();b. getFullDate(); d. getFullYear();
ANS: D PTS: 1 REF: JVS 61
20. The starting date for time calculations is ____.a. January 1, 1970 c. January 1, 1900b. January 1, 1990 d. January 1, 1960
ANS: A PTS: 1 REF: JVS 60
21. After the following code, what value does x contain?
x = new Date("October 31, 2011 11:22:05");x = x.getMinutes();a. 31 c. 11b. 22 d. 5
ANS: B PTS: 1 REF: JVS 61
22. When the someDate variable stores the date object for "June 15, 2011 14:35:28" (which is a Wednesday), the ____ method would return a value of 3.a. someDate.getDate(); c. someDate.getTime();b. someDate.getMonth(); d. someDate.getDay();
ANS: D PTS: 1 REF: JVS 62
23. To change the someDate variable’s year to 2012, you enter ____.a. someDate.setYear(12); c. someDate.setFullYear(2012);b. someDate.setFullYear(12); d. someDate.setYear(2012);
Full file at http://TestbankCollege.eu/Test-Bank-New-Perspectives-on-JavaScript-and-AJAX-Comprehensive-2nd-Edition-Carey
ANS: C PTS: 1 REF: JVS 63
24. Which of the following includes support for daylight savings time?a. computer’s operating system c. Date methodsb. JavaScript d. all of the above
ANS: A PTS: 1 REF: JVS 63
25. Consider the following code:
function showBirthday(birthday) {thisDay = birthday.getDate();thisMonth = birthday.getMonth()+1;thisYear = birthday.getFullYear();return thisMonth + "/" + thisDay + "/" + thisYear;}
What type of parameter must birthday be?a. time object c. check objectb. date object d. none of the above
ANS: B PTS: 1 REF: JVS 63
26. The ____ method extracts the year value from the date variable.a. extractYear() c. Year()b. getFullYear() d. thisYear()
ANS: B PTS: 1 REF: JVS 63
27. To make JavaScript code available to other web pages, the code should be placed in ____.a. the head of the document c. an external fileb. an internal script tag d. a CSS file
ANS: C PTS: 1 REF: JVS 64
28. To tell the browser to include code from the myCode.js file, you should enter ____.a. <script type="text/javascript" link="myCode.js">b. <script type="text/javascript" file="myCode.js">c. <script type="text/javascript" href="myCode.js">d. <script type="text/javascript" src="myCode.js">
ANS: D PTS: 1 REF: JVS 64
29. In a <script> tag linking an external JavaScript file, the MIME type should be specified as ____.a. file/javascript c. mime/javascriptb. text/javascript d. src/javascript
ANS: B PTS: 1 REF: JVS 64
30. To perform a calculation, a statement must include a(n) ____.a. operator c. script fileb. link d. none of the above
Full file at http://TestbankCollege.eu/Test-Bank-New-Perspectives-on-JavaScript-and-AJAX-Comprehensive-2nd-Edition-Carey
ANS: A PTS: 1 REF: JVS 66
31. A(n) ____ operator can be used to perform simple mathematical calculations.a. conditional c. ordinalb. logical d. arithmetic
ANS: D PTS: 1 REF: JVS 66
32. The ____ operator increases a value by 1 (unary operator).a. + c. ++b. * d. ~
ANS: C PTS: 1 REF: JVS 67
33. ____ operators work on two elements in an expression.a. Binary c. Unaryb. Tertiary d. Increment
ANS: A PTS: 1 REF: JVS 67
34. ____ operators work on only one variable.a. Binary c. Solob. Unary d. Increment
ANS: B PTS: 1 REF: JVS 67
35. The most common assignment operator is the ____.a. += c. =b. -= d. ==
ANS: C PTS: 1 REF: JVS 68
36. The expression to return the remainder of x divided by y would be ____.a. x / y c. y / xb. y % x d. x % y
ANS: D PTS: 1 REF: JVS 67
37. In JavaScript, the expression ____ creates the same result as the expression x = x + y;.a. y += x c. y = x ++ yb. x = x++ d. x += y
ANS: D PTS: 1 REF: JVS 68
38. What does the following generic function called foo return?
function foo(){ var y = 3; var x = 4; y = --x; x = y++ % x;
Full file at http://TestbankCollege.eu/Test-Bank-New-Perspectives-on-JavaScript-and-AJAX-Comprehensive-2nd-Edition-Carey
return y;}a. 4 c. 0b. 3 d. 5
ANS: A PTS: 1 REF: JVS 68
39. Which of the following calculates the difference in terms of days?a. days = (newYear - currentDate)/(1000*60*60);b. days = (newYear - currentDate)/(1000*60*24);c. days = (newYear - currentDate);d. days = (newYear - currentDate)/(1000*60*60*24);
ANS: D PTS: 1 REF: JVS 70
40. The ____ can be used for performing advanced calculations and mathematical operations.a. Date object c. Library objectb. Math object d. All of the above
ANS: B PTS: 1 REF: JVS 73
41. To change x's value to the nearest integer, you would use the following code: ____a. Math.round(x); c. math.round(x);b. Math.exp(x); d. math.ceil(x);
ANS: A PTS: 1 REF: JVS 73
42. When using a random number, the function you would least likely use to get an integer value would be ____.a. Math.round() c. Math.ceil()b. Math.floor() d. none of the above
ANS: A PTS: 1 REF: JVS 74
43. The ____ constant has the approximate value of 3.1416.a. Math.X c. Math.PIb. Math.E d. All of the above
ANS: C PTS: 1 REF: JVS 75
44. To display x with only 2 digits, you can apply the ____ method.a. numDigits c. fixDigitsb. toFixed d. toCurrency
ANS: B PTS: 1 REF: JVS 80
45. If x has the value 5.1356, x.toFixed(3) returns what value?a. 5.13 c. $5.13b. $5.135 d. 5.136
ANS: D PTS: 1 REF: JVS 80
46. The ____ method returns a text string with n significant digits to the left or right of the decimal point.a. toPrecision c. toExponential
Full file at http://TestbankCollege.eu/Test-Bank-New-Perspectives-on-JavaScript-and-AJAX-Comprehensive-2nd-Edition-Carey
b. toFixed d. toDigits
ANS: A PTS: 1 REF: JVS 81
47. Given the following code:var result = 10/"A";document.write(result);
What value will be displayed?a. N/A c. NaNb. NonN d. infinity
ANS: C PTS: 1 REF: JVS 79
48. Which function makes sure that a number is not greater than the largest numeric value supported by JavaScript?a. isNaN(value) c. isZero(value)b. isNull(value) d. isFinite(value)
ANS: D PTS: 1 REF: JVS 79
49. When displaying the value 5.78912, JavaScript shows ____ digits by default.a. 0 c. 4b. 2 d. 6
ANS: D PTS: 1 REF: JVS 80
50. If x has the value of 5, then to convert it to a text string, you could use ____.a. myString = x; c. myString = parseText(x);b. myString = x + ""; d. none of the above
ANS: B PTS: 1 REF: JVS 80
51. ____ converts a text string, myString, to a number with decimal places.a. parseText c. parseDecimalb. parseInt d. parseFloat
ANS: D PTS: 1 REF: JVS 81
52. Which of the following returns NaN?a. parseInt("The number of barrels was 12");b. parseInt("135.6");c. parseInt("3 books were read");d. none of the above
ANS: A PTS: 1 REF: JVS 81
53. The general format of the conditional operator is ____.a. (condition) : falseValue ? trueValue c. (condition) ? falseValue : trueValueb. (condition) : trueValue : falseValue d. (condition) ? trueValue : falseValue
ANS: D PTS: 1 REF: JVS 83
54. The ____ comparison operator returns true if variables are equal.
Full file at http://TestbankCollege.eu/Test-Bank-New-Perspectives-on-JavaScript-and-AJAX-Comprehensive-2nd-Edition-Carey
a. != c. >=b. == d. <=
ANS: B PTS: 1 REF: JVS 84
55. The ____ comparison operator returns true if variables are not equal.a. ~= c. !=b. == d. ++
ANS: C PTS: 1 REF: JVS 84
56. The ____ logical operator returns true when both expressions are true.a. || c. ==b. | d. &&
ANS: D PTS: 1 REF: JVS 84
57. The ____ logical operator returns true when either expression is true.a. || c. ==b. | d. &&
ANS: A PTS: 1 REF: JVS 84
58. The ____ logical operator returns true if the expression is false and false if the expression is true.a. || c. &&b. ! d. ==
ANS: B PTS: 1 REF: JVS 84
59. Which of the following assigns y a value of 20 if x is greater than 1 and less than 3 and 15 otherwise?a. y = (x > 1) && (x < 3) : 20 ? 15; c. y = (x > 1) && (x < 3) ? 20 : 15;b. y = (x > 1) && (x < 3) ? 15 : 20; d. y = (x > 1) || (x < 3) ? 20 : 15;
ANS: C PTS: 1 REF: JVS 84
60. Using the figure above, if thisHour is 21, what values will be stored in ampm and thisHour after the last line of code?a. p.m., 9 c. p.m. 10b. a.m., 9 d. a.m., 8
ANS: A PTS: 1 REF: JVS 85
61. A(n) ____ command runs after a specific amount of time.
Full file at http://TestbankCollege.eu/Test-Bank-New-Perspectives-on-JavaScript-and-AJAX-Comprehensive-2nd-Edition-Carey
a. time-delayed c. delayedb. interval-run d. time-interval
ANS: A PTS: 1 REF: JVS 88
62. The general format of the command to specify that a task occur once, after some time, is ____.a. setTime("command", interval); c. setTimeout("command", delay);b. setDelay("command", interval) d. setInterval("command", delay);
ANS: C PTS: 1 REF: JVS 88
63. To indicate that the displayList() method should run once, 15 milliseconds after the page loads, you would use ____.a. onload = "setTimeout("displayList()", 15);"b. onload = "setTimeout('displayList()', 15);"c. onload = "setInterval("displayList()", 15);"d. onload = "setInterval('displayList()', 15);"
ANS: A PTS: 1 REF: JVS 88
64. To give an identification to a command set to run once after a delay, the general syntax is ____.a. timeID = setInterval("command",delay);b. timeID = setDelay("command",delay);c. timeID = setIDTimeout("command",delay);d. timeID = setTimeout("command",delay);
ANS: D PTS: 1 REF: JVS 88
65. Which of the following clears only the command called myDelay that has been set to run once after 30 seconds?a. clearInterval(myDelay); c. clearTimeout(myDelay);b. clearInterval(); d. clearTimeout();
ANS: C PTS: 1 REF: JVS 88
66. A(n) ____ command instructs a browser to run the same command repeatedly.a. timed-interval c. time-delayedb. interval-run d. delayed
ANS: A PTS: 1 REF: JVS 88
67. Which of the following clears only the command called myDelay that has been set to run every 25 seconds?a. clearTimeout(myDelay); c. clearInterval(myDelay);b. clearInterval(); d. clearTimeout();
ANS: C PTS: 1 REF: JVS 89
68. To give an identification to a command set to run repeatedly after a certain amount of time, the general syntax is ____.a. timeID = setTimeout("command",interval);b. timeID = setDelay("command",interval);c. timeID = setIDTimeout("command",interval);
Full file at http://TestbankCollege.eu/Test-Bank-New-Perspectives-on-JavaScript-and-AJAX-Comprehensive-2nd-Edition-Carey
d. timeID = setInterval("command",interval);
ANS: D PTS: 1 REF: JVS 88
69. Given the following code, which function starts running at 30 milliseconds?
setTimeout("superClock()",30);setTimeout("updateMenu()",30);setTimeout("performCalc()",30);a. superClock() c. performCalc()b. updateMenu() d. all of the above
ANS: D PTS: 1 REF: JVS 89
70. To clear all commands set to repeat, you use ____.a. clearTimeout() c. clearDelay()b. clearRepeat() d. clearInterval()
ANS: D PTS: 1 REF: JVS 88
Case-Based Critical Thinking Questions
Case 2-1Legend Films is planning to create a page that will allow users to email their video requests for the studio to add to their online video offerings.
71. In order to add the date to the form, the Web designer could use the ____ object.a. Math c. Arithmeticb. Comparison d. Date
ANS: D PTS: 1 REF: JVS 59 TOP: Critical Thinking
72. The Web designer would like to create code that could be used in each movie new release page to count down to the release. Where should he place the code to make it easy to reuse?a. in a script tag c. in an external fileb. in the head of the document d. none of the above
ANS: C PTS: 1 REF: JVS 64 TOP: Critical Thinking
73. External files containing JavaScript commonly use the extension ____.a. asp c. jsb. script d. php
ANS: C PTS: 1 REF: JVS 65 TOP: Critical Thinking
Case-Based Critical Thinking Questions
Case 2-2Carol Smith wants to create a page that would have several dynamic effects. For instance, she wants a clock that shows how long the user has been viewing a page as well as to have the page show a welcome message and a goodbye message. She also has a list of links that should run her functions to update parts of the page.
Full file at http://TestbankCollege.eu/Test-Bank-New-Perspectives-on-JavaScript-and-AJAX-Comprehensive-2nd-Edition-Carey
74. Carol wants to have the clock update every 10 seconds. Which method would be best for her to use to cause her script to run according to her schedule?a. setInterval c. setTimeoutb. setDelay d. none of the above
ANS: A PTS: 1 REF: JVS 88 TOP: Critical Thinking
75. Carol will most likely use which event to display her welcome message?a. onenter c. onunloadb. onexit d. onload
ANS: D PTS: 1 REF: JVS 57 TOP: Critical Thinking
76. The goodbye message will most likely involve using the ____ event.a. onenter c. onunloadb. onexit d. onload
ANS: C PTS: 1 REF: JVS 57 TOP: Critical Thinking
77. Since Carol is using a list of links to activate JavaScript commands, she will need to use a(n) ____ even though it is no longer considered good design.a. hypertext link c. onclick eventb. external file d. onload event
ANS: A PTS: 1 REF: JVS 58 TOP: Critical Thinking
Case-Based Critical Thinking Questions
Case 2-3Betty's Custom Floral Arrangements shop has an online order form. She has added some JavaScript functions to calculate how much a person has to pay before they submit the page, and now wants to add her functions to her form buttons.
78. Which event is best used for her buttons?a. ondblclick c. onclickb. onkeypress d. onmouseout
ANS: C PTS: 1 REF: JVS 57 TOP: Critical Thinking
79. Betty wants to display the total from her calcTotal() function in her form named results in a text box called finalAmount. What will the command look like?a. results.finalAmount.document.value = calcTotal();b. document.finalAmount.results = calcTotal();c. document.finalAmount.results.value = calcTotal();d. document.results.finalAmount.value = calcTotal();
ANS: D PTS: 1 REF: JVS 55 TOP: Critical Thinking
80. Betty gets complaints that customers are seeing NaN in certain places. What function can help her stop that from happening?a. isFiN c. isNaNb. isNumber d. isFinite
Full file at http://TestbankCollege.eu/Test-Bank-New-Perspectives-on-JavaScript-and-AJAX-Comprehensive-2nd-Edition-Carey
ANS: C PTS: 1 REF: JVS 79 TOP: Critical Thinking
COMPLETION
1. A(n) ____________________ is an attribute added to a Web page element that specifies a program to be run in response to an event.
ANS: event handler
PTS: 1 REF: JVS 56
2. The ____________________ event handler executes when the mouse button is released.
ANS: onmouseup
PTS: 1 REF: JVS 57
3. A(n) ____________________ object is an object containing date information.
ANS: date
PTS: 1 REF: JVS 59
4. The keyword ____________________ indicates that you are creating a new object.
ANS: new
PTS: 1 REF: JVS 59
5. To extract the day of the month from a given date object, JavaScript provides the ____________________ method.
ANS:getDate()getDate
PTS: 1 REF: JVS 60
6. The ____________________ method exists for extracting the value of the current month from a date object.
ANS:getMonth()getMonth
PTS: 1 REF: JVS 61
7. The ____________________ method can be used to set the time of a Date object in milliseconds since January 1, 1970.
Full file at http://TestbankCollege.eu/Test-Bank-New-Perspectives-on-JavaScript-and-AJAX-Comprehensive-2nd-Edition-Carey
ANS:setTime()setTime
PTS: 1 REF: JVS 63
8. A(n) ____________________ is a symbol used to act upon an item or a variable within a JavaScript expression.
ANS: operator
PTS: 1 REF: JVS 66
9. The + operator belongs to a group of operators called ____________________ operators, which perform simple mathematical calculations.
ANS: arithmetic
PTS: 1 REF: JVS 66
10. The ____________________ operator can be used to increase the value of a variable by 1.
ANS:increment++
PTS: 1 REF: JVS 67
11. To subtract one from a variable named count before using it, you should use the ____________________ operator.
ANS:decrement--
PTS: 1 REF: JVS 67
12. In "y = ++x;" , x is ____________________ before y is assigned a value.
ANS: incremented
PTS: 1 REF: JVS 68
13. When subtracting one date from another, the answer is measured in ____________________.
ANS: milliseconds
PTS: 1 REF: JVS 70
14. A(n) ____________________ statement is one that runs only when specific conditions are met.
Full file at http://TestbankCollege.eu/Test-Bank-New-Perspectives-on-JavaScript-and-AJAX-Comprehensive-2nd-Edition-Carey
ANS: conditional
PTS: 1 REF: JVS 83
15. A(n) ____________________ operator compares the value of one element with that of another.
ANS: comparison
PTS: 1 REF: JVS 83
16. " x = y== 2 ? 45 : 50;" is an example of a(n) ____________________.
ANS:conditionalconditional operator
PTS: 1 REF: JVS 83
17. The ____________________ operator returns true if two expressions are true.
ANS: &&
PTS: 1 REF: JVS 84
18. If x has the value of false, then !x returns ____________________.
ANS: true
PTS: 1 REF: JVS 84
19. A(n) ____________________ command runs once after a specified amount of time passes.
ANS: time-delayed
PTS: 1 REF: JVS 88
20. If you have six commands set with an interval of 100, they will all run at the ____________________ time.
ANS: same
PTS: 1 REF: JVS 89
MATCHING
Identify the letter of the choice that best matches the phrase or definition.a. arithmetic operator g. binary operatorb. negation operator h. logical operatorc. conditional operator i. comparison operatord. date object j. Math object
Full file at http://TestbankCollege.eu/Test-Bank-New-Perspectives-on-JavaScript-and-AJAX-Comprehensive-2nd-Edition-Carey
e. unary operator k. increment operatorf. date method l. event handler
1. Allows you to connect several expressions2. A ternary operator that executes a test3. Has methods for rounding numbers4. Requires two operands5. Used to create expressions that have true or false values6. Perform simple calculations7. Changes an item's sign8. Can be placed before or after an operand9. Requires one operand
10. Tells browsers what code to run11. Retrieves information from a date object12. Created using Date();
1. ANS: H PTS: 1 REF: JVS 842. ANS: C PTS: 1 REF: JVS 833. ANS: J PTS: 1 REF: JVS 724. ANS: G PTS: 1 REF: JVS 675. ANS: I PTS: 1 REF: JVS 836. ANS: A PTS: 1 REF: JVS 667. ANS: B PTS: 1 REF: JVS 688. ANS: K PTS: 1 REF: JVS 679. ANS: E PTS: 1 REF: JVS 67
10. ANS: L PTS: 1 REF: JVS 5611. ANS: F PTS: 1 REF: JVS 6012. ANS: D PTS: 1 REF: JVS 59
ESSAY
1. Given a date object
Date(“June 15, 2011, 14:35:28”)
stored in a variable called Today, list six date methods to extract and display individual component values of this date object. (Note: this date is a Wednesday.)
ANS:Today.getSeconds() [value is 28]Today.getMinutes() [value is 35]Today.getHours() [value is 14]Today.getDate() [value is 15]Today.getDay() [value is 3]Today.getMonth() [value is 5]Today.getFullYear() [value is 2011]Today.getTime() [value is 1,308,166,505,000].
PTS: 1 REF: JVS 59 | JVS 62 TOP: Critical Thinking
Full file at http://TestbankCollege.eu/Test-Bank-New-Perspectives-on-JavaScript-and-AJAX-Comprehensive-2nd-Edition-Carey
2. List the assignment operators and describe each one.
ANS:= Assigns the value of the expression on the right to the expression on the left+= Adds two expressions–= Subtracts the expression on the right from the expression on the left*= Multiplies two expressions%= Calculates the remainder from dividing the expression on the left by the expression on the right.
PTS: 1 REF: JVS 69 TOP: Critical Thinking
3. Write the methods to run a command after a delay, to repeat a command at set intervals, to cancel a time-delayed command, and to cancel a repeated command.
ANS:To run a command after a delay, use the method:
timeID = setTimeout(“command”,delay);where command is the command to be run, delay is the delay time in milliseconds, and timeID is a variable that stores the id associated with the time-delayed command.
To repeat a command at set intervals, use the method:timeID = setInterval(“command”, interval);
where interval is the interval, in milliseconds, before the command is to run again.
To cancel a time-delayed command, use the method:clearTimeout(timeID);
where timeID is the id of the time-delayed command. To clear all time-delayed commands, use the method clearTimeout().
To cancel a repeated command, use the method:clearInterval(timeID);
where timeID is the id of the repeated command. To clear all repeated commands, use the method clearInterval().
PTS: 1 REF: JVS 87 | JVS 89 TOP: Critical Thinking