Head First JavaScript Code: Chapter 11, Kill Bugs Dead

Chapter 11 Opening Image

Even the best laid JavaScript plans sometimes fail.

Head First JavaScript

When this happens, and it will, your job is not to panic. The best JavaScript developers are not the ones who never create bugs—those people are called liars. No, the best JavaScript developers are those who are able to successfully hunt down and eradicate the bugs they create. More importantly, top notch JavaScript bug exterminators develop good coding habits that minimize the sneakiest and nastiest of bugs. A little prevention can go a long way. But bugs happen, and you’ll need an arsenal of weapons to combat them...

Download the Code

Code Description and Viewing

Bug Scene Investigators

The Bug Scene Investigators example consists of two different buggy web pages, an IQ calculator page and a radio call-in page, that are corrected incrementally throughout the chapter. Each numbered HTML file corresponds to an incremental version of each of these web pages. 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. The Call button ONLY completely works for a winning caller if the page is opened from a real web server. The button WON'T fully work when the page is opened directly from your local hard disk because the PHP server script that is invoked on a winning call requires a web server. This doesn't limit the JavaScript code in any way.

  • case1_1.html - BSI Case 1 (IQ calculator) web page chock full of bugs (page 489)
  • case1_2.htmll - BSI Case 1 (IQ calculator) web page with the missing parentheses bug fixed (page 491)
  • case1_3.html - BSI Case 1 (IQ calculator) web page with the missing curly brace bug fixed (page 494)
  • case1_4.htmll - BSI Case 1 (IQ calculator) web page with the variable name typo bug fixed (page 496)
  • case2_1.html - BSI Case 2 (radio call-in) web page with loads of bugs (page 499)
  • case2_2.html - BSI Case 2 (radio call-in) web page with Bug #1 fixed (page 501)
  • case2_3.html - BSI Case 2 (radio call-in) web page with Bug #2 fixed (page 506)
  • case2_4.html - BSI Case 2 (radio call-in) web page with Bug #3 fixed (page 510)
  • case2_5.html - BSI Case 2 (radio call-in) web page with the custom debugging console added (page 520)
  • case2_6.html - BSI Case 2 (radio call-in) web page with the debugging console creation bug fixed (page 524)
  • case2_7.html - BSI Case 2 (radio call-in) web page with all of the checkWinner() function commented out (page 528)
  • case2_8.htmll - BSI Case 2 (radio call-in) web page with an important line of the CheckWinner() function uncommented (page 529)
  • case2_9.html - BSI Case 2 (radio call-in) web page with Bug #4 fixed (page 530)
  • debug.js - External JavaScript code to help in debugging by offering a debug console
  • radiocall.php - PHP server script that processes radio call-ins for the BSI Case 2 (radio call-in) web page
  • brain.png - Brain image that appears in the BSI Case 1 (IQ calculator) web page
  • radio.png - Radio image that appears in the BSI Case 2 (radio call-in) web page