Head First JavaScript Code: Chapter 5, Looping

Chapter 5 Opening Image

Some say repetition is the spice of life.

Head First JavaScript

Sure, doing something new and interesting is certainly exciting, but it's the little repetitive things that really make it possible to get through the day. Compulsive hand sanitizing, a nervous tick, clicking Reply To All to every freaking message you receive! Okay, maybe repetition isn't always such a great thing in the real world. However, it can be extremely handy in the world of JavaScript. You'd be surprised how often you need a script to run a piece of code several times. Without loops, you'd be wasting a lot of time cutting and pasting a bunch of wasteful code.

Download the Code

Code Description and Viewing

Mandango

The Mandango web page is built incrementally throughout the chapter. Each numbered HTML file corresponds to an incremental version of the web page. When a page number appears beside a file, it is either the page where the file's contents are presented or the exercise (solution) corresponding to the file.

  • mandango1.html - Mandango web page with single-seat search (page 208)
  • mandango2.html - Mandango web page with break used to fix loop problem (page 214)
  • mandango3.html - Mandango web page with three-seat search (page 220)
  • mandango4.html - Mandango web page reworked to use a while loop (page 230)
  • mandango5.html - Mandango web page with two-dimensional array of seats (page 236-237)
  • seat_select.png - Selected movie seat image that appears on the Mandango web page
  • seat_avail.png - Available movie seat image that appears on the Mandango web page
  • seat_unavail.png - Unavailable movie seat image that appears on the Mandango web page