HTML and CSS Reference
In-Depth Information
To create the peek() function:
1. Return to the hanjie.js file in your text editor.
2. Directly after the changeBackground() function, insert the following peek() func-
tion (see Figure 13-21):
function peek() {
/* Create collection of cells that should be marked */
var markedCells = document.querySelectorAll(“#hanjieGrid
/* Create collection of cells that should be empty */
var emptyCells = document.querySelectorAll(“#hanjieGrid
Figure 13-21
insert the peek() function
Next, the function needs to loop through those two collections and identify the incor-
rect cells. A marked cell is incorrect if it is displayed with a white background, and an
empty cell is incorrect if it is displayed with a gray background (a gold background indi-
cates an unknown status and thus is never incorrect). The function then will change those
background colors to pink and red, respectively.
To change the background color for incorrect cells:
1. Add the following code to the peek() function as shown in Figure 13-22:
/* Display every incorrect white cell in pink */
for (var i = 0; i < markedCells.length; i++) {
cell = markedCells[i];
if ( == “white”) = “rgb(255, 192, 192)”;
/* Display every incorrect darkened cell in red */
for (var i = 0; i < emptyCells.length; i++) {
var cell = emptyCells[i];
if ( == “rgb(101, 101, 101)”) = “red”;
Search WWH ::

Custom Search