Skip to content

Commit 7bb06bb

Browse files
committed
Generated random colors for each tile mainly using the Math object to produce a unique hex color code.
1 parent 823ba54 commit 7bb06bb

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

script.js

+2-13
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,11 @@ function JQCode() {
99
for (var i = 0; i < 9; i++) {
1010
for (var j = 0; j < 9; j++) {
1111
let $tileElement = $('<div class="tile"></div>');
12+
let randomColor = '#' + Math.floor(Math.random() * 12323232).toString(16);
1213
$tileElement.css('width', '11.1%');
1314
$tileElement.css('float', 'left');
1415
$tileElement.css('paddingBottom', '11.1%');
15-
if (i % 2 === 0) {
16-
if (j % 2 === 0) {
17-
$tileElement.css('background', 'salmon');
18-
} else {
19-
$tileElement.css('background', 'rebeccapurple');
20-
}
21-
} else if(i % 2 !== 0){
22-
if (j % 2 === 0) {
23-
$tileElement.css('background', 'rebeccapurple');
24-
} else {
25-
$tileElement.css('background', 'salmon');
26-
}
27-
}
16+
$tileElement.css('background', randomColor);
2817
$tileElement.css('margin', 'auto');
2918
$('body').append($tileElement);
3019
}

0 commit comments

Comments
 (0)