INFO263 Final Text Book Questions

Ace your homework & exams now with Quizwiz!

Using regular expressions, write a JavaScript function to test whether the word fox exists in the string The quick brown fox .

A JavaScript function using regular expressions to test whether the word fox exists in the string The quick brown fox could be as follows: document.write(/fox/.test("The quick brown fox"))

Using regular expressions, write a PHP function to replace all occurrences of the word the in The cow jumps over the moon with the word my .

A PHP function using a regular expression to replace all occurrences of the word the in The cow jumps over the moon with the word my could be as follows: $s=preg_replace("/the/i", "my", "The cow jumps over the moon");

How can you draw a complex curve with two imaginary attractors?

A complex curve with two imaginary attractors is called a Bézier curve. To create one, call the bezierCurveTo method, supplying two pairs of x and y coordinates for the attractors, followed by another pair for the end point of the curve. A curve is then created from the current drawing location to the destination.owkey34

Write a regular expression to match any single word followed by any nonword character.

A regular expression to match any single word followed by any nonword character could be /\w+\W/g .

Write a regular expression to match either of the words fox or fix .

A regular expression to match either of the words fox or fix could be /f[oi]x/.

Write a statement to sort an array of numbers in descending numerical order.

A statement to sort an array of numbers into descending numerical order would look like this: numbers.sort(function(a, b){ return b - a })

How many properties and how many methods does an XMLHttpRequest object have?

An XMLHttpRequest object has six properties and six methods (see Tables 17-1 and 17-2).

Given a pair of CSS rules with equal precedence, how can you make one have greater precedence than the other?

Given a pair of CSS declarations with equal precedence, to make one have greater precedence over the other, you append the !important declaration to it, like this: p { color:#ff0000 !important; }

In CSS rules, what is the purpose of the semicolon?

In CSS, the semicolon ( ; ) is used as a separator between declarations.

Which character is used by CSS to represent any element?

In CSS, you can match any element using the * universal selector.

What feature is new in HTML5 and offers greater capability than cookies?

In HTML5, local storage offers far greater access to local user space than cookies, which are limited in the amount of data they can hold.

Which HTML5 technology supports running background JavaScript tasks?

In HTML5, you can set up web workers to carry out background tasks for you. These workers are simply sections of JavaScript code.

Which characters are used to prefix (a) IDs and (b) class names in a CSS rule?

In a CSS declaration, ID names are prefixed with a # character (e.g., #myid ) and class names with a . character (e.g., .myclass).

Why is it necessary to write a function for creating new XMLHttpRequest objects?

It's necessary to write a function for creating new XMLHttpRequest objects because Microsoft browsers use two different methods of creating them, while all other major browsers use a third. By writing a function to test the browser in use, you can ensure that your code will work on all major browsers.

Are JavaScript functions and variable names case-sensitive or case-insensitive?

JavaScript functions and variable name are case-sensitive. The variables Count, count , and COUNT are all different.

What keyword is used to create an object?

New objects are created via the new keyword.

Name a way to return multiple values from a function.

One way to return multiple values from a function is to place them all inside an array and return the array.

Write a regular expression to match any characters that are not in a word, as defined by regular expression syntax.

Regular of expressions to match , characters not in a word /[^\w]/, /[\W]/, /^\w/, /\W/ /[^a-zA-Z0-9_]/ , and so on.

What HTML attribute is used to precomplete form fields with a value?

The HTML attribute used to precomplete form fields with a value is value which is placed within an <input> tag and takes the form value="value ".

What is the difference between a CSS ID and a CSS class?

The difference between a CSS ID and a CSS class is that an ID is applied to only a single element, whereas a class can be applied to many elements.

What is the best way for web workers to communicate with a main program?

The easiest way for a web worker to communicate with a main program is by using the postMessage method to send information. The program attaches to the web worker's onmessage event to retrieve it.

How many items of data per pixel are returned by the getImageData method?

The getImageData method returns an array containing the pixel data for the specified area, with the elements consecutively containing the red, green, blue, and alpha pixel values, so four items of data are returned per pixel.

What are the main differences between an asynchronous GET and POST request?

The main differences between asynchronous GET and POST requests are that GET requests append the data to the URL rather than passing it as a parameter of the send method, while POST requests pass the data as a parameter of the send method and require the correct form headers to be sent first.

Do all the methods of a class have to be defined within the class definition?

The methods of a class do not have to be defined within the class definition. If a method is defined outside the constructor, the method name must be assigned to the this object within the class definition.

What new HTML5 element enables drawing of graphics in web pages?

The new HTML5 element for drawing graphics in a web page is the canvas element, created with the <canvas> tag.

What is the purpose of the try...catch construct?

The purpose of the try...catch construct is to set an error trap for the code inside the try statement. If the code causes an error, the catch section will be executed instead of a general error being issued.

What XMLHttpRequest object property returns an asynchronous call's text response?

The responseText property of an XMLHttpRequest object contains the value returned by a successful asynchronous call.

What XMLHttpRequest object property returns an asynchronous call's XML response?

The responseXML property of an XMLHttpRequest object contains a DOM tree created from the XML returned by a successful asynchronous call.

What syntax is used to create an associative array?

The syntax you would use to create an associative array is key : value , within curly braces, as in the following: assocarray = { "forename" : "Paul", "surname" : "McCartney", "group" : "The Beatles" }

What are the three main parts that make up a jQuery page, and how are they denoted?

The three main parts of a jQuery page are its header, content, and footer. To denote these, you place them within <div> elements that respectively have their data-role attributes assigned the values header , content , and footer . These three elements must be children of the parent <div> discussed in Question 2.

Which two parameters to the transform method apply to scaling operations?

The transform method takes six arguments (or parameters), which are, in order, horizontal scale, horizontal skew, vertical skew, vertical scale, horizontal translate, and vertical translate. Therefore, the arguments that apply to scaling are the first and fourth in the list.

How can you add a comment to a stylesheet?

To add a comment to a stylesheet, you enclose it between /* and */ opening and closing comment markers.

How can you add an icon to a button?

To add an icon to a button, supply the name of a known jQuery Mobile icon as a value to its data-icon attribute; for example, data-icon="gear".

How can you adjust the width of lines when drawing?

To adjust the width of drawn lines, assign a value to the lineWidth property of the context, like this: context.lineWidth = 5

How do you create a canvas element in HTML?

To create a canvas element in HTML, use the <canvas> tag and specify an ID that Java Script can use to access it, like this: <canvas id='mycanvas'>

How can you create gradient fills of more than two colors?

To create a gradient fill (either radial or linear) with more than two colors, specify all the colors required as stop colors assigned to a gradient object you have already created, and assign them each a starting point as a percent value of the complete gradient (between 0 and 1 ), like this: gradient.addColorStop(0, 'green') gradient.addColorStop(0.3, 'red') gradient.addColorStop(0,79, 'orange') gradient.addColorStop(1, 'brown')

How can you create a multidimensional array?

To create a multidimensional array, place subarrays inside the main array.

What HTML would you use to define a page of content to jQuery Mobile?

To define a page of content to jQuery Mobile, you should enclose it within a <div> element with a data-role attribute of page .

How can you determine whether a browser supports local storage?

To determine whether a browser supports local storage, test the typeof property of the localStorage object, like this: if (typeof localStorage == 'undefined') // Local storage is not available

Which HTML tag attribute is used to directly embed a style into an element?

To directly embed a style into an element, use the style attribute, like this: <div style='color:blue;'>

Which method would you use to specify a section of a canvas such that future drawing takes place only within that area?

To ensure that future drawing takes place only within a certain area, you can create a path and then call the clip method.

What method can you call to erase all local storage data for the current domain?

To erase all local storage data for the current domain, you can call the local Storage.clear method.

How do you give JavaScript access to a canvas element?

To give JavaScript access to a canvas element, ensure the element has been given an ID such as mycanvas , and then use the document.getElementdById function (or the O function from the OSC.js file supplied with the examples archive on the companion website) to return an object to the element. Finally, call getContext on the object to retrieve a 2D context to the canvas, like this: canvas = document.getElementById('mycanvas') context = canvas.getContext('2d')

How many audio codecs should you use to guarantee maximum playability on all platforms?

To guarantee maximum audio playability on all platforms, you should use at least two codecs: PCM and any of the others, or Vorbis and any of the others.

Which two video codecs should you use to guarantee maximum playability on all platforms?

To guarantee maximum video playability on all platforms, you should use the MP4/H.264 codec, and the Ogg/Theora or VP8 codec to support the Opera browser.

What HTML tag can you use to import a stylesheet into a document?

To import a stylesheet into a document, you can use the HTML <link> tag: <link rel='stylesheet' href='styles.css'>

Which directive do you use to import one stylesheet into another (or the <style> section of some HTML)?

To import one stylesheet into another, you use the directive, like this: @import url('styles.css');

Which HTML5 tags would you use to incorporate audio and video in a web page?

To incorporate audio or video in a web page, use the <audio> or <video> tags.

What XMLHttpRequest method is used to initiate an asynchronous request?

To initiate an asynchronous request, an XMLHTTPRequest object's send method is called.

Which two HTML element tags are used to insert audio and video into an HTML5 document?

To insert audio and video into an HTML5 document, use the <audio> and <video> tags.

How can you make a jQuery Mobile element display inline like a element, rather than full width like a <div>?

To make a jQuery Mobile element display inline, you give its data-inline attribute a value of true.

How can you easily make an anchor link display as a button?

To make an anchor link display as a button, give its data-role attribute a value of button.

How can you make cross-document messaging more secure?

To make cross-document messaging more secure, you should always supply a domain identifier when posting messages, like this: postMessage(message, 'http://mydomain.com') And check for that identifier when receiving them, like this: if (event.origin) != 'http://mydomain.com') // Disallow You can also encrypt or obscure communications to discourage injection or eavesdropping.

What JavaScript method is used to match a string against a regular expression?

To match a string against a regular expression in JavaScript, use the method.

Which methods can you call to play and pause HTML5 media playback?

To play and pause HTML5 media playback, you can call the play and pause methods of an <audio> or <video> element.

How can you prevent a web page from being loaded asynchronously?

To prevent a web page from being loaded asynchronously you can either give the anchor's or form's data-ajax property a value of false , give its rel attribute a value of external , or supply a value to its target attribute.

How can you put more than one jQuery Mobile page within an HTML document?

To put multiple jQuery Mobile pages within a single HTML document you can include multiple parent <div> elements with a data-role attribute of page , each containing the three child <div>'s discussed in Question 3. To link between these pages, you should assign each of these elements a unique id (such as id="news"), which can then be referenced from anywhere within the HTML document using an anchor such as <a href='#news'>.

What method do you call to request geolocation data from a web browser?

To request geolocation data from a web browser, you call the following method, passing the names of two functions you have written for handling access to or denial of the data: navigator.geolocation.getCurrentPosition(granted, denied)

How can you select a group of different elements and/or element types in CSS?

To select a group of different elements and/or element types in CSS, you place a comma between each element, ID, or class.

How would you set the page transition of an anchor to flip, rather than using the default of fade?

To set the page transition of an anchor to flip, give its data-transition attribute a value of flip (or you can use any other of the supported values for the other available transition effects; for example, data-transition="pop" ).

How can you specify a callback function to handle asynchronous responses?

To specify a callback function to handle asynchronous responses, assign the function name to the XMLHttpRequest object's onreadystatechange property. You can also use an unnamed, inline function.

How do you start and finish the creation of a canvas path?

To start a canvas path, issue the beginPath method on the context. After creating a path, you close it by issuing closePath on the context, like this: context.beginPath() // Path creation commands go here context.closePath()

How can you stop a web worker from running?

To stop a web worker from running, issue a call to the terminate method of the worker object, like this: worker.terminate()

How can you support media playback in a non-HTML5 browser?

To support media playback in a non-HTML5 browser, you can embed a Flash audio or video player inside any <audio> or <video> element, which will be activated if HTML5 media playing is not supported.

How can you write a function that accepts and processes an unlimited number of parameters?

To write a function that accepts and processes an unlimited number of parameters, access parameters through the arguments array, which is a member of all functions.

Name a couple of major benefits and one downside to using a CDN for delivering jQuery Mobile to a web browser.

Using a CDN to deliver files means you do not have to rely on your own (or your client's) bandwidth, which can save money. Additionally, you can speed up the user's experience because, once a browser has downloaded a file, the same version can be reloaded locally from the cache. A downside is that your web page or web app may not run locally if the user's browser is not connected to the internet at the time.

How do you know whether an asynchronous call completed successfully?

When an asynchronous call successfully completes, the object's status property will have a value of 200.

When you're defining a class, what keyword do you use to refer to the current object?

When defining a class, use the this keyword to refer to the current object.

What method can you use to extract data from a canvas into an image?

You can extract the data from a canvas using the toDataURL method, which can then be assigned to the src property of an image object, like this: image.src = canvas.toDataURL()

How can you load a page so that it displays as a dialog rather than a web page?

You can load a page so that it displays as a dialog by giving its data-rel attribute a value of dialog.

How can you make a property or method available to all objects in a class without replicating the property or method within the object?

You can make a property or method available to all objects in a class without replicating it within the object by using the prototype keyword to create a single instance, which is then passed by reference to all the objects in the class.

To support drag-and-drop operations, how can you prevent the default action of disallowing dragging and dropping for these events?

You can prevent the default action of disallowing dragging and dropping for the events that handle these operations by issuing a call to the event object's preventDefault method in your ondragover and ondrop event handlers.

What JavaScript method can you use to send a form for validation prior to submitting it?

You can send a form for validation prior to submitting it by adding the JavaScript onsubmit attribute to the tag. Make sure that your function returns true if the form is to be submitted, and false otherwise.

How can you tell when an asynchronous call has completed?

You can tell that an asynchronous call has completed when the readyState property of an object has a value of 4 .

What programming language is required to access many of the advanced HTML5 features?

You need to use JavaScript to access many of the new HTML5 features, such as the canvas and geolocation.


Related study sets

World Regional Geography (Chapter 5) Exam II

View Set

Passpoint - Gastrointestinal Disorders

View Set

Motion - Speed, Velocity and Acceleration

View Set

womens health final exam chap 23, 24, 25, 34, 35, 36, 37

View Set

Accounting Book Questions Chapter one

View Set