HTML and CSS Reference
3. Scroll up to the changeBackground() function. Add the following code to the end
of the function, as shown in Figure 13-35, so that the app tests for a complete
solution each time the user clicks a cell and changes its color:
/* Check the puzzle solution */
calling the checksolution() function
4. Close the hanjie.js file, saving your changes.
To test your code, you'll load another set of puzzles that Rebecca has developed. The
first puzzle in the set is a simple 5 Í 5 puzzle with the upper diagonal cells filled in,
which you can quickly and easily solve.
To test the checkSolution() function:
1. Return to the hanjie.htm file in your text editor.
2. Locate the script element that loads the grids.js file, and then change the source
to the grids2.js file. Close the file, saving your changes.
3. Reload the hanjie.htm file in your Web browser.
4. With the first puzzle selected, solve the puzzle by filling in the upper-left corner
of the grid with darkened cells and changing the color of the lower-right corner
to white, as shown in Figure 13-36. When you have finished solving the puzzle, an
alert box should automatically appear, congratulating you, as shown in the figure.