forked from gSchool/checkerboard-exercise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
41 lines (29 loc) · 1.02 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function createCheckerBoard() {
var div = document.createElement('div');
div.id = "Checkerboard";
div.style.display = "flex";
div.style.flexWrap = "wrap";
div.style.width = "800px";
div.style.height = "800px";
document.body.appendChild(div);
var table = document.createElement('table');
table.style.borderCollapse = "collapse";
for (let i = 0; i < 8; i++) {
var row = document.createElement('tr');
for (let j = 0; j < 8; j++) {
var tile = document.createElement('td');
tile.style.width = "100px";
tile.style.height = "100px";
// If the sum of row and column indices is even, make it black; otherwise, make it red.
if ((i + j) % 2 === 0) {
tile.style.backgroundColor = 'black';
} else {
tile.style.backgroundColor = 'red';
}
row.appendChild(tile);
}
table.appendChild(row);
}
div.appendChild(table);
}
createCheckerBoard();