From 871d2c6b7aa097f861f3770bd850f93d69d09ca9 Mon Sep 17 00:00:00 2001 From: dillontouchard Date: Wed, 15 Nov 2023 13:11:46 -0800 Subject: [PATCH 1/2] red and black checkerboard --- index.html | 4 +++- script.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 3ed1f6df..f1cd6f00 100644 --- a/index.html +++ b/index.html @@ -10,5 +10,7 @@ } - + +
+ diff --git a/script.js b/script.js index e69de29b..b7d47854 100644 --- a/script.js +++ b/script.js @@ -0,0 +1,37 @@ +var container = document.createElement('container') +document.body.appendChild(container) +container.style.display = 'flex' +container.style.flexWrap = 'wrap' +container.style.height = '800px' +container.style.width = '800px' + + +function makeSquareRed() { + let div = document.createElement('div') + div.style.height = "12.5%" + div.style.width = "12.5%" + div.style.backgroundColor = 'red' + container.appendChild(div) +} + + +function makeSquareBlack() { + let div = document.createElement('div') + div.style.height = "12.5%" + div.style.width = "12.5%" + div.style.backgroundColor = 'black' + container.appendChild(div) +} + + +var row = 0 +for (var i = 1; i < 65; i++) { + if (i % 2 === 1 && row % 2 === 0 || i % 2 === 0 && row % 2 === 1) { + makeSquareRed() + } else { + makeSquareBlack() + } + if (i % 8 === 0 && i != 0) { + row++ + } +} \ No newline at end of file From f55cb45c1cc64e0fb2335f57e49d6d8cd48ea583 Mon Sep 17 00:00:00 2001 From: dillontouchard Date: Wed, 15 Nov 2023 13:41:27 -0800 Subject: [PATCH 2/2] RandomColors --- script.js | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/script.js b/script.js index b7d47854..7d808e00 100644 --- a/script.js +++ b/script.js @@ -5,7 +5,21 @@ container.style.flexWrap = 'wrap' container.style.height = '800px' container.style.width = '800px' - +function makeRandomColor() { + let letters = '0123456789ABCDEF'; + let color = '#'; + for (let i = 0; i < 6; i++) { + color += letters[Math.floor(Math.random() * 16)]; + } + return color; +} +function makeSquareRandomColor() { + let div = document.createElement('div') + div.style.height = "12.5%" + div.style.width = "12.5%" + div.style.backgroundColor = makeRandomColor(); + container.appendChild(div) +} function makeSquareRed() { let div = document.createElement('div') div.style.height = "12.5%" @@ -23,15 +37,6 @@ function makeSquareBlack() { container.appendChild(div) } - -var row = 0 -for (var i = 1; i < 65; i++) { - if (i % 2 === 1 && row % 2 === 0 || i % 2 === 0 && row % 2 === 1) { - makeSquareRed() - } else { - makeSquareBlack() - } - if (i % 8 === 0 && i != 0) { - row++ - } +for (var i = 0; i < 64; i++) { + makeSquareRandomColor(); } \ No newline at end of file