Meeting 10
Understanding Functions
10.1 Homework Discussion
Professor: How was y our homework? Are we read y to play Su doku?
Maria: We can c heck placed numbers but we didn’t implement a user interface.
Professor: Don’t worry about that. Soon you will learn how to do a user interface as
well. Please, show me what you’ve got.
Maria: These ar e the variables that we used:
var number = 3, row = 4, col = 3;
var exists = false;
var i, j;
var iStart, jStart;
The variables number, row and col define a number that we want to place in a grid
and where we want to place it. We used an auxiliary variable exists for pretty much
the same purpose as we did last time in our lottery program .
In the last line we declared the variables iStart and jStart, w hich will hold the
indexes of the upper left cell of a 3 × 3 box. We used these ind exes as a starting
position for searching a box for a number.
Since each row is an array, checking a row was the most straightforward task:
//Checks a row:
if (initial[row].indexOf(number) != -1) {
exists = true;
}
Just slightly more complicated was chec king the column. We had to check each cell
separately:
187
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.118.159