Menu

(Solved) : Use Strict Var Function Id Return Documentgetelementbyid Id Var Imagecache Var Imagecounte Q43977468 . . .

application In this exercise, youll enhance the Slide Show application by adding buttons to LACICISt 7-2 start and pause the

Chapter 7 How to work with links, images, and timers 6. Test the application again and click the Start button to make sure th

“use strict”;
var $ = function (id) { return document.getElementById(id); };

var imageCache = [];
var imageCounter = 0;
var timer;

var runSlideShow = function() {
imageCounter = (imageCounter + 1) % imageCache.length;
var image = imageCache[imageCounter];
$(“image”).src = image.src;
$(“caption”).firstChild.nodeValue = image.title;
};

window.onload = function () {
var listNode = $(“image_list”); // the ul element
var links = listNode.getElementsByTagName(“a”);
  
// Preload image, copy title properties, and store in array
var i, link, image;
for ( i = 0; i < links.length; i++ ) {
link = links[i];
image = new Image();
image.src = link.getAttribute(“href”);
image.title = link.getAttribute(“title”);
imageCache[imageCache.length] = image;
}

// Attach start and pause event handlers
$(“start”).onclick = function() {
  
};
$(“pause”).onclick = function() {
  
};
};

application In this exercise, you’ll enhance the Slide Show application by adding buttons to LACICISt 7-2 start and pause the slide show. Fishing Slide Show Stant Pause Catch and Release Open and test the application 1. Use your text editor or IDE to open the HTML and JavaScript files in this folder: javascript_jqueryexercisesch07slideshow Use Chrome to test this application. Notice that the slideshow isn’t running, the Pause button is disabled, and nothing happens when you click on the Start 2. button. Add code to start the slide show when the Start button is clicked 3. Review the code in the index.html file, and notice that the disabled attribute of the Pause button is set to “true”. That makes sense because the user shouldn’t be able to click this button if the slide show isn’t running. 4. Review the code in the slide_show.js file, and note that the code for running the slide show is coded in a function named runSlideShow() and the imageCache, imageCounter, and timer variables are coded as global variables so they can be accessed by the runSlideShow() and onload() functions. 5. Within the onload event handler, add code to the click event handler of the Start button that creates a timer that runs the slide show and changes the slide every 2 seconds. In addition, add code that disables the Start button and enables the Pause button. To disable a button, you can set its disabled attribute to true. To enable a button, you can remove its disabled attribute. Chapter 7 How to work with links, images, and timers 6. Test the application again and click the Start button to make sure the slide show is working. Notice that there’s a delay of 2 seconds before the next slide is displayed. 7. Add code to the click event handler of the Start button that calls the runSlideShow() function before the timer is started. Then, test the application again to see that the next slide is displayed immediately when the Start button is clicked. Add code to pause the slide show when the Pause button is clicked 8. Add code to the click event handler of the Pause button that cancels the timer. In addition, add code that enables the Start button and disables the Pause button. Test the application again, click the Start button to start the slide show, and then click the Pause button to pause the slide show. Click the Start button again to re-start the slide show. When you’re done testing, close the browser. 9. Show transcribed image text application In this exercise, you’ll enhance the Slide Show application by adding buttons to LACICISt 7-2 start and pause the slide show. Fishing Slide Show Stant Pause Catch and Release Open and test the application 1. Use your text editor or IDE to open the HTML and JavaScript files in this folder: javascript_jqueryexercisesch07slideshow Use Chrome to test this application. Notice that the slideshow isn’t running, the Pause button is disabled, and nothing happens when you click on the Start 2. button. Add code to start the slide show when the Start button is clicked 3. Review the code in the index.html file, and notice that the disabled attribute of the Pause button is set to “true”. That makes sense because the user shouldn’t be able to click this button if the slide show isn’t running. 4. Review the code in the slide_show.js file, and note that the code for running the slide show is coded in a function named runSlideShow() and the imageCache, imageCounter, and timer variables are coded as global variables so they can be accessed by the runSlideShow() and onload() functions. 5. Within the onload event handler, add code to the click event handler of the Start button that creates a timer that runs the slide show and changes the slide every 2 seconds. In addition, add code that disables the Start button and enables the Pause button. To disable a button, you can set its disabled attribute to true. To enable a button, you can remove its disabled attribute.
Chapter 7 How to work with links, images, and timers 6. Test the application again and click the Start button to make sure the slide show is working. Notice that there’s a delay of 2 seconds before the next slide is displayed. 7. Add code to the click event handler of the Start button that calls the runSlideShow() function before the timer is started. Then, test the application again to see that the next slide is displayed immediately when the Start button is clicked. Add code to pause the slide show when the Pause button is clicked 8. Add code to the click event handler of the Pause button that cancels the timer. In addition, add code that enables the Start button and disables the Pause button. Test the application again, click the Start button to start the slide show, and then click the Pause button to pause the slide show. Click the Start button again to re-start the slide show. When you’re done testing, close the browser. 9.

Expert Answer


Answer to “use strict”; var $ = function (id) { return document.getElementById(id); }; var imageCache = []; var imageCounter = 0; …

OR