Which of the following statements runs a function named newTimer every 3 seconds?

1)

Which of the following statements runs a function named newTimer every 3 seconds?

(1pts)

setTimeout(newTimer, 3);

setTimeout(newTimer, 3000);

setInterval(newTimer, 3);

setInterval(newTimer, 3000);

2)

Code example 7-1
1. var eventHandler = function(evt) {
2.     if (!evt) { evt = window.event; }
3.     if (evt.preventDefault) {
4.         evt.preventDefault();
5.     }
6.     else {
7.         evt.returnValue = false;
8.     }
9. };

(Refer to code example 7-1) Which line gets the event object for older versions of IE?

(1pts)

line 2

line 3

line 4

line 7

3)

Why might you want to preload images on a page that uses rollovers?

(1pts)

To prevent delays displaying the images when the swapped images are large.

To prevent delays displaying the images when the connection is slow.

To prevent delays when the page is being loaded.

All of the above.

A and B only.

4)

Code Example 7-3
The JavaScript::
1. var $ = function(id) {
2.      return document.getElementById(id);
3. };
4. var timer;
5. var counter = 10;
6. var updateCounter = function() {
7.      counter–;
8.      $(“counter”).firstChild.nodeValue = counter;
9.      if (counter <= 0)   {
10.         clearInterval(timer);
11.         document.getElementById(“counter”).innerHTML = “Blastoff!”;
12.     }
13. };
14. window.onload = function() {
15.     timer = setInterval ( updateCounter, 1000 );
16. };

The HTML:
<h3>Countdown: <span id=”counter”> 10 </span> </h2>

(Refer to Code Example 7-3) The timer in this code will update the counter

(1pts)

every 10 seconds

once, after a delay of 1000 milliseconds

immediately, when the page loads

every second for 10 times

5)

Code Example 7-2
JavaScript code for an Image Swap
1. var $ = function(id) {
2.     return document.getElementById(id);
3. };
4. window.onload = function() {
5.      var listNode = $(“image_list”);
6.      var captionNode = $(“caption”);
7.      var imageNode = $(“main_image”);
8.      var imageLinks = listNode.getElementsByTagName(“a”);
9.      var i, image, linkNode, link;
10.     for ( i = 0; i < imageLinks.length; i++ ) {
11.         linkNode = imageLinks[i];
12.         image = new Image();
13.         image.src = linkNode.getAttribute(“href”);
14.         linkNode.onclick = function(evt) {
15.             link = this;
16.             imageNode.src = link.getAttribute(“href”);
17.             captionNode.firstChild.nodeValue = link.getAttribute(“title”);
18.             if (!evt) { evt = window.event; }
19.             if (evt.preventDefault) { evt.preventDefault(); }
20.             else { evt.returnFalse = false; }
21.         };
22.     }
23.     imageLinks[0].focus();
24. };

(Refer to Code Example 7-2) What does the this keyword on line 15 refer to?

(1pts)

the image that’s currently being processed

the link that’s currently being processed

the link that the user clicked on

the array of link nodes

6)

The easiest way to create a timer that will repeat its function at intervals but will begin immediately is to

(1pts)

have the timer call an anonymous function

specify 0 milliseconds as the interval

call the function before you create the timer

create a one-time timer that runs when the page loads and then use an the interval timer after that

7)

Code Example 7-2
JavaScript code for an Image Swap
1. var $ = function(id) {
2.     return document.getElementById(id);
3. };
4. window.onload = function() {
5.      var listNode = $(“image_list”);
6.      var captionNode = $(“caption”);
7.      var imageNode = $(“main_image”);
8.      var imageLinks = listNode.getElementsByTagName(“a”);
9.      var i, image, linkNode, link;
10.     for ( i = 0; i < imageLinks.length; i++ ) {
11.         linkNode = imageLinks[i];
12.         image = new Image();
13.         image.src = linkNode.getAttribute(“href”);
14.         linkNode.onclick = function(evt) {
15.             link = this;
16.             imageNode.src = link.getAttribute(“href”);
17.             captionNode.firstChild.nodeValue = link.getAttribute(“title”);
18.             if (!evt) { evt = window.event; }
19.             if (evt.preventDefault) { evt.preventDefault(); }
20.             else { evt.returnFalse = false; }
21.         };
22.     }
23.     imageLinks[0].focus();
24. };

(Refer to Code Example 7-2) What would happen if lines 18 through 20 were omitted?

(1pts)

The code would only work in older versions of IE.

Clicking on a link would open a new browser window or tab and display the image specified by the href attribute of the link.

Nothing would happen when the user clicks on one of the links.

Clicking on a link would cause the caption, but not the larger image, associated with the link to be displayed.

8)

Code Example 7-3
The JavaScript::
1. var $ = function(id) {
2.      return document.getElementById(id);
3. };
4. var timer;
5. var counter = 10;
6. var updateCounter = function() {
7.      counter–;
8.      $(“counter”).firstChild.nodeValue = counter;
9.      if (counter <= 0)   {
10.         clearInterval(timer);
11.         document.getElementById(“counter”).innerHTML = “Blastoff!”;
12.     }
13. };
14. window.onload = function() {
15.     timer = setInterval ( updateCounter, 1000 );
16. };

The HTML:
<h3>Countdown: <span id=”counter”> 10 </span> </h2>

(Refer to Code Example 7-3) Which of the following statements about this code is true?

(1pts)

It creates a timer that displays a counter on the page that replaces the text “Countdown”.

It creates a timer that uses the setInterval() method to change the updateCounter value every 1000 milliseconds .

It creates a timer that counts down from 10 to 1 and displays “Blastoff!” in the span element when the counter variable reaches 0.

It will fail because a timer cannot count down.

9)

You need to provide cross-browser compatible code to cancel the default action of an event

(1pts)

so the event can be handled with a single event handler

to ensure that all browsers store the event object in the global window.event property

because older IE browsers weren’t completely DOM-compliant

to ensure that all browsers use the preventDefault() method

10)

The img elements for the thumbnails in the code that follows are coded within the <a> elements
<main>
<h1>Image Swap</h1>
<p>Click on an image to enlarge.</p>
<ul id=”image_list”>
<li><a href=”images/pic1.jpg” title=”dogs”>
<img src=”thumbnails/t1.jpg” alt=””></a></li>
<li><a href=”images/pic2.jpg” title=”cats”>
<img src=”thumbnails/t2.jpg” alt=””></a></li>
</ul>
<h2 id=”caption”>Animals</h2>
<p><img id=”main_image” src=”images/pic1.jpg” alt=””></p>

</main>

(1pts)

so the user can swap the main image by pressing Enter when a thumbnail has the focus

so the user can access the thumbnail links by pressing the Tab key

so the application is easy to use by the motor-impaired

all of the above

11)

Code Example 7-2
JavaScript code for an Image Swap
1. var $ = function(id) {
2.     return document.getElementById(id);
3. };
4. window.onload = function() {
5.      var listNode = $(“image_list”);
6.      var captionNode = $(“caption”);
7.      var imageNode = $(“main_image”);
8.      var imageLinks = listNode.getElementsByTagName(“a”);
9.      var i, image, linkNode, link;
10.     for ( i = 0; i < imageLinks.length; i++ ) {
11.         linkNode = imageLinks[i];
12.         image = new Image();
13.         image.src = linkNode.getAttribute(“href”);
14.         linkNode.onclick = function(evt) {
15.             link = this;
16.             imageNode.src = link.getAttribute(“href”);
17.             captionNode.firstChild.nodeValue = link.getAttribute(“title”);
18.             if (!evt) { evt = window.event; }
19.             if (evt.preventDefault) { evt.preventDefault(); }
20.             else { evt.returnFalse = false; }
21.         };
22.     }
23.     imageLinks[0].focus();
24. };

(Refer to Code Example 7-2) Which lines of code attach an event handler for the click event of each link?

(1pts)

line 8

lines 11 – 13

lines 14 – 17

line 14 – 21

12)

Which HTML element does NOT have a default action associated with the click event?

(1pts)

<input>

<button>

<img>

<a>

13)

Code example 7-1
1. var eventHandler = function(evt) {
2.     if (!evt) { evt = window.event; }
3.     if (evt.preventDefault) {
4.         evt.preventDefault();
5.     }
6.     else {
7.         evt.returnValue = false;
8.     }
9. };

(Refer to code example 7-1) This is cross-browser compatible code that cancels the default action for an event. What do lines 3 – 5 do?

(1pts)

They cancel the default action of the event for all modern browsers.

They check to see if an event has been triggered.

They cancel the default action of the event for older versions of IE.

They check to see if the page is DOM-compliant.

14)

Which of the following is NOT true about the event object that is created when an event occurs?

(1pts)

To cancel the default action of an event, you first need to create an event handler.

The event object contains information about the event that occurred.

The event object provides methods that let you control the behavior of the event.

The event object is always passed to function that handles the event.

15)

Which of the following statements runs a function named newTimer once after 3 seconds?

(1pts)

setTimeout(newTimer, 3);

setTimeout(newTimer, 3000);

setInterval(newTimer, 3);

setInterval(newTimer, 3000);

Expert Answer


1) setInterval(newTimer,3000);

setTimeout(function, milliseconds) executes a function, . . .

Leave a Comment

App

We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.

Contact

info@coursedeep.com

+91 8634554387