Full file at https://fratstock.eu Tutorial 2: Working with Operators and Expressions

Similar documents
LECTURE-3. Exceptions JS Events. CS3101: Programming Languages: Javascript Ramana Isukapalli

LECTURE-2. Functions review HTML Forms. Arrays Exceptions Events. CS3101: Scripting Languages: Javascript Ramana Isukapalli

Fundamentals of Website Development

New Perspectives on Creating Web Pages with HTML. Tutorial Objectives

Such JavaScript Very Wow

INTRODUCTION TO WEB DEVELOPMENT AND HTML. Lecture 15: JavaScript loops, Objects, Events - Spring 2011

Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript

Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript

JAVASCRIPT BASICS. Handling Events In JavaScript. In programing, event-driven programming could be a programming

Objectives. Introduction to JavaScript. Introduction to JavaScript INFS Peter Y. Wu, RMU 1

INFS 2150 Introduction to Web Development and e-commerce Technology. Programming with JavaScript

CISH-6510 Web Application Design and Development. Overview of JavaScript. Overview

PES DEGREE COLLEGE BANGALORE SOUTH CAMPUS 1 K.M. before Electronic City, Bangalore WEB PROGRAMMING Solution Set II

JavaScript by Vetri. Creating a Programmable Web Page

Events: another simple example

Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world

Web Programming and Design. MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh

Introduction to DHTML

Place User-Defined Functions in the HEAD Section

HTML User Interface Controls. Interactive HTML user interfaces. Document Object Model (DOM)

Lecture 14. Introduction to JavaScript. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

Client-Side Web Technologies. JavaScript Part I

Key features. Nothing to do with java It is the Client-side scripting language Designed to add interactivity to HTML pages

710 Index Attributes, 127 action attribute, 263 assigning, bottom attribute, domain name attribute, 481 expiration date attribute, 480 8

Outline. Lecture 4: Document Object Model (DOM) What is DOM Traversal and Modification Events and Event Handling

3Lesson 3: Functions, Methods and Events in JavaScript Objectives

What Is JavaScript? A scripting language based on an object-orientated programming philosophy.

Note: Java and JavaScript are two completely different languages in both concept and design!

Want to add cool effects like rollovers and pop-up windows?

Unit 3. Operators. School of Science and Technology INTRODUCTION

CECS 189D EXAMINATION #1

CSS The web browser uses its own resources, and eases the burden on the server. It has fewer features than server side scripting.

JavaScript code is inserted between tags, just like normal HTML tags:

HTML5 and CSS3 More JavaScript Page 1

COMS 469: Interactive Media II

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

By the end of this section of the practical, the students should be able to:

Javascript Methods. concat Method (Array) concat Method (String) charat Method (String)

JavaScript Handling Events Page 1

CSC Javascript

1$ 5 ! $ 6 4 * Source: 0 "!*! 0! * 8 97 ?!$ 5 0 *! 4! $ 0 : * ' () 7;7 7<7

JavaScript CS 4640 Programming Languages for Web Applications

JavaScript CS 4640 Programming Languages for Web Applications

Introduction to JavaScript

Photo from DOM

write vs. writeln Prompting as Page Loads Today s Goals CSCI 2910 Client/Server-Side Programming Intermediate File vs. HTML Output

CS1520 Recitation Week 2

About the Author. Liability

Javascript Hierarchy Objects Object Properties Methods Event Handlers. onload onunload onblur onfocus

link document.getelementbyid("coffee").style.borderwidth = "0px" document.getelementbyid("tea").style.borderwidth = "10px"

Introduction to JavaScript, Part 2

8/19/2018. Web Development & Design Foundations with HTML5. Learning Objectives (1 of 2) Learning Objectives (2 of 2) What is JavaScript?

Princess Nourah bint Abdulrahman University. Computer Sciences Department

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

JavaScript is described in detail in many books on the subject, and there is excellent tutorial material at

Web Development & Design Foundations with HTML5

Chapter 1 Introduction to Computers and the Internet

Coding in JavaScript functions

Beijing , China. Keywords: Web system, XSS vulnerability, Filtering mechanisms, Vulnerability scanning.

JavaScript: The Basics

PIC 40A. Lecture 10: JS: Wrapper objects, Input and Output, Control structures, random numbers. Copyright 2011 Jukka Virtanen UCLA 1 04/24/17

C ITS 1231 Web Tec hnolog ies. JavaScript: Document, Event, Date objects

A Balanced Introduction to Computer Science, 3/E

JavaScript Tutorial for Programmers

TEXTAREA NN 2 IE 3 DOM 1

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

A Balanced Introduction to Computer Science, 3/E David Reed, Creighton University 2011 Pearson Prentice Hall ISBN

JavaScript and XHTML. Prof. D. Krupesha, PESIT, Bangalore

UNIT 3 SECTION 1 Answer the following questions Q.1: What is an editor? editor editor Q.2: What do you understand by a web browser?

Installation and Configuration Manual

4. Inputting data or messages to a function is called passing data to the function.

COMP519 Web Programming Lecture 16: JavaScript (Part 7) Handouts

DC71 INTERNET APPLICATIONS JUNE 2013

Operators. Java operators are classified into three categories:

A.A. 2008/09. Why introduce JavaScript. G. Cecchetti Internet Software Technologies

The first sample. What is JavaScript?

EVENT-DRIVEN PROGRAMMING

Canvas & Brush Reference. Source: stock.xchng, Maarten Uilenbroek

Functions, Randomness and Libraries

Like most objects, String objects need to be created before they can be used. To create a String object, we can write

Lesson 3: Basic Programming Concepts

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

JSF - H:INPUTSECRET. Class name of a validator that s created and attached to a component


introjs.notebook March 02, 2014

JS Tutorial 3: InnerHTML Note: this part is in last week s tutorial as well, but will be included in this week s lab

Multiple Choice Questions, COPA, Semester-2. Dr.V.Nagaradjane

JavaScript: Events, the DOM Tree, jquery and Timing

Web Programming/Scripting: JavaScript

UNIT - III. Every element in a document tree refers to a Node object. Some nodes of the tree are

Full file at Excel Chapter 2 - Formulas, Functions, Formatting, and Web Queries

Operators. Lecture 3 COP 3014 Spring January 16, 2018

DOM Primer Part 2. Contents

Then there are methods ; each method describes an action that can be done to (or with) the object.

5. Strict mode use strict ; 6. Statement without semicolon, with semicolon 7. Keywords 8. Variables var keyword and global scope variable 9.

Chapter 2 Working with Data Types and Operators

More on new. Today s Goals. CSCI 2910 Client/Server-Side Programming. Creating/Defining Objects. Creating/Defining Objects (continued)

Outcomes Week 2 Overview Describe the inputs, activities, and outputs of each step in the software development life cycle. Describe arithmetic, relati

JAVASCRIPT BASICS. JavaScript Math Functions. The Math functions helps you to perform mathematical tasks

A Balanced Introduction to Computer Science, 3/E David Reed, Creighton University 2011 Pearson Prentice Hall ISBN

Transcription:

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". 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 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: F DateObject.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 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(). 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. document b. 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 operator b. 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. onerror b. 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. onkeydown b. 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 only b. 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. onfocus b. onchange d. onblur ANS: C PTS: 1 REF: JVS 57 7. To add code that runs when content of an input field has been modified, you use the event handler. a. onload c. onfocus b. 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. onfocus b. 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. onkeypress

b. onclick d. onchange ANS: B PTS: 1 REF: JVS 56 10. Which of the following is not a Window event? a. onresize c. onscroll b. onselect d. onmove ANS: B PTS: 1 REF: JVS 57 11. Which of the following is not a mouse event? a. onmousedown c. onmouseclick b. onmouseup d. onmouseout ANS: C PTS: 1 REF: JVS 57 12. Which of the following is not a keyboard event? a. onkeyout c. onkeypress b. 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. hypertext b. 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. ids b. 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> 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. 4 b. 1 d. 10 ANS: A PTS: 1 REF: JVS 59 18. Dates are numeric values measured in. a. milliseconds c. microseconds b. 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, 1900 b. 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. 11 b. 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); 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 methods b. 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 object b. 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 file b. 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/javascript b. 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 file b. link d. none of the above ANS: A PTS: 1 REF: JVS 66 31. A(n) operator can be used to perform simple mathematical calculations. a. conditional c. ordinal b. 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. Unary b. Tertiary d. Increment ANS: A PTS: 1 REF: JVS 67 34. operators work on only one variable. a. Binary c. Solo b. 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 / x b. 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 ++ y b. 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; return y; } a. 4 c. 0 b. 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 object b. 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.PI b. 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. fixdigits b. 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.13 b. $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 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. NaN b. 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. 4 b. 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. parsedecimal b. 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 : truevalue b. (condition) : truevalue : falsevalue d. (condition)? truevalue : falsevalue ANS: D PTS: 1 REF: JVS 83 54. The comparison operator returns true if variables are equal. 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. 10 b. 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. a. time-delayed c. delayed b. 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-delayed

b. 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); 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-1 Legend 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. Arithmetic b. 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 file b. 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. js b. script d. php ANS: C PTS: 1 REF: JVS 65 TOP: Critical Thinking Case-Based Critical Thinking Questions Case 2-2 Carol 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. 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. settimeout b. 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. onunload b. 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. onunload b. 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 event b. external file d. onload event ANS: A PTS: 1 REF: JVS 58 TOP: Critical Thinking Case-Based Critical Thinking Questions Case 2-3 Betty'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. onclick b. 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. isnan b. isnumber d. isfinite 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. 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. 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: conditional conditional 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 operator b. negation operator h. logical operator c. conditional operator i. comparison operator d. date object j. Math object

e. unary operator k. increment operator f. date method l. event handler 1. Allows you to connect several expressions 2. A ternary operator that executes a test 3. Has methods for rounding numbers 4. Requires two operands 5. Used to create expressions that have true or false values 6. Perform simple calculations 7. Changes an item's sign 8. Can be placed before or after an operand 9. Requires one operand 10. Tells browsers what code to run 11. Retrieves information from a date object 12. Created using Date(); 1. ANS: H PTS: 1 REF: JVS 84 2. ANS: C PTS: 1 REF: JVS 83 3. ANS: J PTS: 1 REF: JVS 72 4. ANS: G PTS: 1 REF: JVS 67 5. ANS: I PTS: 1 REF: JVS 83 6. ANS: A PTS: 1 REF: JVS 66 7. ANS: B PTS: 1 REF: JVS 68 8. ANS: K PTS: 1 REF: JVS 67 9. ANS: E PTS: 1 REF: JVS 67 10. ANS: L PTS: 1 REF: JVS 56 11. ANS: F PTS: 1 REF: JVS 60 12. 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 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