-
Notifications
You must be signed in to change notification settings - Fork 0
/
chessBoard.js
83 lines (68 loc) · 1.33 KB
/
chessBoard.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//variable grid size
//tries
//just x first - odd rows start w space, even with #
var size = 8;
var chess = "";
for (var x = 0; x < size; x++) {
if (x % 2 == 0)
chess += "0";
else
chess += "#";
}
console.log(chess);
/*returns
0#0#0#0#
has extra space bc of console.log adds it
*/
//ok now 2d - using 0's instead of spaces bc it's easier for me to read
var size = 8;
var chess = "";
for(var y = 0; y < size; y++) {
for (var x = 0; x < size; x++) {
if (x % 2 == 0)
chess += "0";
else
chess += "#";
}
chess += "\n"
}
console.log(chess);
/*returns
0#0#0#0#
0#0#0#0#
0#0#0#0#
0#0#0#0#
0#0#0#0#
0#0#0#0#
0#0#0#0#
0#0#0#0#
*/
/*ok this logs 0#0#0#0# everyline bc it is looking thru x=1,2....8 which is the same on everyline.
changing to y % 2 = 0 would log 00000000 for odd lines and ######## for even lines. to switch, test (x+y) % = 0
*/
var size = 12;
var chess = "";
for(var y = 0; y < size; y++) {
for (var x = 0; x < size; x++) {
if ((x+y) % 2 == 0)
chess += " ";
else
chess += "#";
}
chess += "\n"
}
console.log(chess);
/*returns
# # # # # #
# # # # # #
# # # # # #
# # # # # #
# # # # # #
# # # # # #
# # # # # #
# # # # # #
# # # # # #
# # # # # #
# # # # # #
# # # # # #
first line has extra space bc of console.log