Appendix
Answers to Self Tests
Chapter 1: Introduction to JavaScript
  1.  C. HTML
  2.  A. A Web browser
  3.  C. JavaScript
  4.  B. False
  5.  C. ECMAScript
  6.  A. True
  7.  C. LiveScript
  8.  A. prototype-based
  9.  B. client
10.  B. It can validate the information before it is sent to the server.
11.  C. scripting
12.  A. True
13.  D. The client/Web browser
14.  D. It is added to an HTML document.
15.  A. <script> and </script> HTML tags
Chapter 2: Placing JavaScript in an HTML File
  1.  D. All of the above
  2.  B. To ensure the Web page validates when using XHTML
  3.  A. Yes
  4.  The noscript tag provides content for those without JavaScript.
  5.  A. .js
  6.  B. <script type= “text/javascript” src=“yourfile.js”></script>
  7.  In HTML, the script tag is not case sensitive. However, with XHTML, the script tag must be in lowercase.
  8.  D. semicolon
  9.  A. document.write()
10.  C. When the script is very long or needs to be placed in more than one HTML document
11.  JavaScript comments can be very useful for the purpose of documenting or debugging your code.
12.  C. //
13.  A. /*
14.  D. */
15.  A. close
Chapter 3: Using Variables
  1.  A variable represents or holds a value.
  2.  A. They can save you time in writing and updating your scripts, and they can make the purpose of your code clearer.
  3.  To declare a variable, you use the var keyword.
  4.  D. =
  5.  C. var pagenumber = 240;
  6.  B. False
  7.  A variable name must begin with a letter, a dollar, or an underscore character.
  8.  A. True
  9.  B. var my_house;
10.  In JavaScript, the data types include number, string, Booleans, null, and undefined.
11.  To denote an exponent in JavaScript, you use a letter e right after the base number and before the exponent.
12.  C. var mytext = “Here is some text!’;
13.  D. document.write(“John said, “Hi!””);
14.  Special characters enable you to add things to your strings that could not be added otherwise.
15.  B. document.write(“I like to ” + myhobby + “ every weekend”);
Chapter 4: Using Functions
  1.  In general, a function is a little script within a larger script that is used to perform a single task or a series of tasks.
  2.  B. They provide a way to organize the various parts of the script into the different tasks that must be accomplished, and they can be reused.
  3.  On the first line of a function, you declare it as a function, name it, and indicate whether it accepts any arguments.
  4.  C. function
  5.  A. Curly brackets – {}
  6.  A. True
  7.  B. False
  8.  C. function get_text()
  9.  Arguments are used to allow a function to import one or more values from somewhere outside the function.
10.  B. parentheses – ()
11.  D. Comma
12.  D. window.alert(“This is text”);
13.  B. some_alert(“some”, “words”);
14.  A. var shopping = get_something();
15.  A global variable can be used anywhere in JavaScript.
Chapter 5: JavaScript Operators
  1.  A(n) operator is a symbol or word in JavaScript that performs some sort of calculation, comparison, or assignment on one or more values.
  2.  Arithmetic operators are most often used to perform mathematical calculations on two values.
  3.  The addition operator adds two values.
  4.  When the increment operator is placed before the operand, it increases the value of the operand by 1, and then the rest of the statement is executed.
  5.  D. $#
  6.  A. Assigns a new value to a variable
  7.  The add-and-assign (+=) operator adds the value on the right side of the operator to the variable on the left side and then assigns that new value to the variable.
  8.  C. Compares two values or statements, and returns a value of true or false
  9.  A. 4!=3
10.  D. 4<=3
11.  The logical operators allow you to compare two conditional statements to see if one or both of the statements is true and to proceed accordingly.
12.  B. !(17>=20)
13.  B. (4>=4) && (5<=2)
14.  Bitwise operators are logical operators that work at the bit level.
15.  In JavaScript, the operators have a certain order of precedence.
Chapter 6: Conditional Statements and Loops
  1.  A conditional statement is a statement that you can use to execute a bit of code based on a condition, or do something else if that condition is not met.
  2.  You can think of a conditional statement as being a little like cause and effect.
  3.  A. True
  4.  B. if (y < 7)
  5.  C. Curly brackets
  6.  The switch statement allows you to take a single variable value and execute a different line of code based on the value of the variable.
  7.  A loop is a block of code that allows you to repeat a section of code a certain number of times.
  8.  B. False
  9.  A. for (var x = 1; x < 6; x += 1)
10.  A while loop looks at a comparison and repeats until the comparison is no longer true.
11.  B. while (x = 7)
12.  A. True
13.  B. False
14.  B. False
15.  D. As many times as you like
Chapter 7: JavaScript Arrays
  1.  An array is a way of storing a list of data.
  2.  In JavaScript, there are two ways to define an array.
  3.  In an array, access to an element is achieved through the use of a(n) index.
  4.  You can use a loop to cycle through all of the items in an array.
  5.  B. False
  6.  D. var if = new Array[10];
  7.  B. False (this accesses the sixth item, cool[4] accesses the fifth)
  8.  C. Creates an array with five items
  9.  A. The length property
10.  Array literal notation allows you to create an array using square brackets, without the need to write out “new Array”.
11.  The concat() method is used to combine the elements of two or more arrays and return a new array containing all of the elements.
12.  The join() method is used to combine the elements of an array into a single string, with each element separated by a specified character.
13.  The pop() method is used to remove the last element from an array.
14.  C. It sorts the contents using string character codes.
15.  Nested arrays provide the ability to create arrays of more than one dimension.
Chapter 8: Objects
  1.  An object is a collection of properties and values.
  2.  When creating single objects, you can use the object constructor or object literal notation.
  3.  A. True
  4.  B. dot operator
  5.  When you need to use a variable to access a property name, you can use bracket notation.
  6.  A constructor function can be used to create an object structure.
  7.  An instance of an object can be created using the new keyword.
  8.  B. False
  9.  C. Assuming the myhouse object exists, it assigns the value of the kitchen property of the myhouse object to the variable x.
10.  If a property cannot be found in the object instance, JavaScript will look in the object’s prototype.
11.  B. window.alert(“You are using ” + navigator.appName);
12.  C. Assuming the myhouse object exists, the kitchen property is assigned a new string value of “big” or is initialized with the value “big”.
13.  In JavaScript, there are many predefined objects you can use to gain access to certain properties and methods you may need.
14.  The navigator object gives you access to the various properties of the viewer’s browser.
15.  C. appType
Chapter 9: The Document Object
  1.  The document object is an object that is created by the browser for each new HTML page that is viewed.
  2.  The referrer property of the document object returns the URL of the document that referred the viewer to the current document.
  3.  A. True
  4.  D. getElementById()
  5.  B. False (it is added as the last child node rather than the first)
  6.  B. False
  7.  The anchors property of the document object is an array that contains all of the anchor (<a>) tags on the page.
  8.  The innerHTML DOM node property allows you to change the HTML content of an element node.
  9.  The lastModified property holds the value of the date and time the current document was last modified.
10.  A. True
11.  A. True
12.  C. URL
13.  C. It adds a JavaScript newline character at the end of the line.
14.  C. All the elements that have the same value for the name attribute (most commonly radio buttons).
15.  B. document.write() and document.writeln() statements
Chapter 10: Event Handlers
  1.  A. True
  2.  Event handlers are useful because they enable you to gain access to the events that may occur on the page.
  3.  To use an event handler, you can place it in the HTML or the JavaScript code.
  4.  C. <input type=“button” onclick=“window.alert(‘Hey there!’);”>
  5.  The load event occurs when a Web page has finished loading.
  6.  D. The viewer moves the mouse cursor over an element on the page.
  7.  B. False
  8.  The unload event occurs when the viewer leaves the current Web page.
  9.  The blur event is the opposite of the focus event.
10.  The event object contains properties and methods for an event.
11.  The type property of an event contains the type of event that occurred.
12.  The submit event occurs when the viewer submits a form on a Web page.
13.  A. True
14.  In Internet Explorer prior to version 9, the event object can be accessed by using window.event.
15.  The addEventListener() method and the attachEvent() method are two new ways to register events.
Chapter 11: Window Object
  1.  A window object is created for each window that appears on the screen.
  2.  A. True
  3.  The length property holds the value of the number of frames within a window.
  4.  A. True
  5.  The name property holds the name of the current window and also allows you to give the window a name.
  6.  A. The window object is the global object for JavaScript in Web browsers.
  7.  The self property is another way of saying “the current window” in JavaScript.
  8.  C. Newer browsers do not allow the window status to be changed by default, so the user would need to change security settings in order for it to work.
  9.  A. The parent property goes to the top of the current frame set, while the top property goes to the top window of all frame sets on the page.
10.  The alert() method pops up a message to the viewer, and the viewer has to click an OK button to continue.
11.  A. true
12.  The print() method enables the viewer to print the current window.
13.  The prompt() method is used to prompt the viewer to enter information.
14.  D. yes, no, 1, and 0
15.  B. The setInterval() method is used to repeat a function at a set time interval, while setTimeout() executes a function only once after a set time delay.
Chapter 12: Math, Number, and Date Objects
  1.  A. Take the square roots and other such values of strings and return a number
  2.  The E property holds the value of Euler’s constant.
  3.  The LN10 property holds the value of the natural logarithm of 10.
  4.  B. False
  5.  C. document.write(Math.PI);
  6.  The SQRT2 property holds the value of the square root of 2.
  7.  C. absolute
  8.  The asin() method returns the arcsine of a number sent to it as an argument.
  9.  The pow() method returns the numeric value of the first argument raised to the power of the second argument.
10.  C. var rand_int= Math.floor(Math.random()*8);
11.  The sqrt() method returns the square root of a number sent to it as an argument.
12.  D. An instance of the Date object
13.  The getDay() method returns the number of days into the week.
14.  B. False
15.  B. var weekday= rightnow.getDay();
Chapter 13: Handling Strings
  1.  The String object provides properties and methods to get information about strings or to modify strings.
  2.  A. Creating an instance of the String object and creating a string literal
  3.  You can create a string literal by assigning a string value to a variable.
  4.  C. JavaScript takes the string literal and turns it into a temporary String object
  5.  C. length
  6.  The length property returns the length of a string.
  7.  B. var the_text = “Look at me!”;
  8.  B. charAt()
  9.  The big() method adds <big> and </big> tags around a string value.
10.  The concat() method combines two or more strings together and returns the new combined string value.
11.  D. The indexOf() method returns a numeric value that is the position of a character sent as a parameter, but only the position of the first occurrence of that character.
12.  Cookie information is stored in the document.cookie property.
13.  The toString() method returns the string literal value of a string.
14.  To replace information in a string, you can use regular expressions and the replace() method of the String object.
15.  The match() method compares a regular expression and a string to see whether they match.
Chapter 14: JavaScript and Forms
  1.  Each time you add a set of <form> and </form> tags to an HTML document, a form object is created.
  2.  The forms array allows you to access a form using an index number.
  3.  B. document.forms[3]
  4.  A. document.forms[2].length
  5.  C. document.forms.length
  6.  Using form names or ids allows you to name the forms on the page that you want to access later.
  7.  A. document.f1.e1.value
  8.  The action property allows you to access the value of the action=“url” attribute in the opening form tag.
  9.  The elements property is an array that allows you to access each element in a specific form.
10.  The pattern attribute in HTML 5 allows you to give a form field a regular expression it must validate.
11.  The reset() method allows you to reset a form using your script.
12.  C. <meter min=“0” max=“10” value=“8”>8</meter>
13.  One way to help with form accessibility is to use the <label></label> tags to identify what field a piece of text is describing.
14.  The submit() method allows you to submit a form without the viewer clicking the submit button.
15.  C. required
Chapter 15: An Introduction to Advanced Techniques
  1.  Frames divide a window into two or more separate areas, each containing different content.
  2.  Frames differ from tables because the divisions in a frame set contain separate HTML documents.
  3.  The <frameset></frameset> tags are used to create a frame set.
  4.  A single frame is created with the <frame></frame> tags.
  5.  The cols attribute divides a frame set into columns.
  6.  The src property of an <img> element allows you to change an image.
  7.  A. The frames array or a frame name
  8.  A. True
  9.  C. jsLint
10.  B. alert() and console.log()
11.  A. top
12.  B. XMLHttpRequest
13.  AJAX stands for Asynchronous JavaScript and XML.
14.  A. True
15.  The acronym for JavaScript Object notation is JSON.
Chapter 16: JavaScript Libraries, HTML5, and Harmony
  1.  C. $(document).ready()
  2.  B. $(“#story”).hide();
  3.  CSS syntax is used to select elements in jQuery.
  4.  The jQuery library makes it easier to write code that is cross-browser.
  5.  The <canvas> element allows you to use JavaScript to draw on a defined area of the page.
  6.  B. False
  7.  The draggable attribute of an element defines whether or not the element can be dragged.
  8.  JavaScript libraries may make some advanced coding tasks easier by making the code easier to write.
  9.  B. False
10.  The dragstart event occurs when an element begins being dragged.
11.  B. event.dataTransfer
12.  D. getData()
13.  B. const
14.  C. let
15.  Any answer is correct!
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.255.5