From 797a3c59c12d386a6b15b39fe91ade79bc66eb02 Mon Sep 17 00:00:00 2001 From: Bar Yaakov Date: Fri, 20 Jun 2025 13:13:16 -0400 Subject: [PATCH 1/4] initial commit --- main.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/main.js b/main.js index 79a0fd1..3e788d0 100644 --- a/main.js +++ b/main.js @@ -5,3 +5,17 @@ root.addEventListener("click", (event) => { console.log(event.target.tagName); console.log(event.target); }); + +const addRow = document.getElementById("add-row"); +{ + addRow.addEventListener("click", () => + { + + + + + }); + + + +} \ No newline at end of file From d1829d2ad7b292f5822eb205b25a3c089ef69388 Mon Sep 17 00:00:00 2001 From: Elian Echavarria Date: Fri, 20 Jun 2025 15:44:39 -0400 Subject: [PATCH 2/4] elian-colors-done --- main.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index 79a0fd1..bc00c00 100644 --- a/main.js +++ b/main.js @@ -1,7 +1,29 @@ // Please feel free to change the JS as you see fit! This is just a starting point. +const colorDropdown = document.getElementById("color-select"); +const fillButton = document.getElementById("fill-grid"); + +let selectedColor = colorDropdown.value; + +colorDropdown.addEventListener("change", () => { + selectedColor = colorDropdown.value; +}) + + + const root = document.getElementById("root"); root.addEventListener("click", (event) => { - console.log(event.target.tagName); - console.log(event.target); + // console.log(event.target.tagName); + // console.log(event.target); + if (event.target.tagName === "TD") { + event.target.style.backgroundColor = selectedColor; + } }); + + +fillButton.addEventListener('click', () => { + const cells = document.getElementsByTagName("td"); + for (let i = 0; i < cells.length; i++) { + cells[i].style.backgroundColor = selectedColor; + } +}) From 5387f981de24470c46ae95a92c87325eb9514f02 Mon Sep 17 00:00:00 2001 From: Bar Yaakov Date: Fri, 20 Jun 2025 19:30:31 -0400 Subject: [PATCH 3/4] finished all 10 --- index.html | 3 ++ main.js | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 119 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 1a138b6..35b743f 100644 --- a/index.html +++ b/index.html @@ -33,12 +33,15 @@

Grid Maker

+ + +
diff --git a/main.js b/main.js index 3e788d0..cb05efa 100644 --- a/main.js +++ b/main.js @@ -7,15 +7,127 @@ root.addEventListener("click", (event) => { }); const addRow = document.getElementById("add-row"); + +addRow.addEventListener("click", () => +{ + const nmberOfColumns = document.getElementsByTagName("TR")[0].children.length; + + const newRow = document.createElement("TR"); + document.getElementsByTagName("tbody")[0].appendChild(newRow); + + for (let i = 0; i < nmberOfColumns; i++) + { + const newCell = document.createElement("TD"); + newRow.appendChild(newCell); + } +}); + +const addColunm = document.getElementById("add-column"); + +addColunm.addEventListener("click", () => +{ + const nmberOfRows = document.getElementsByTagName("TR").length; + + for (let i = 0; i < nmberOfRows; i++) + { + const newCell2 = document.createElement("TD") + document.getElementsByTagName("TR")[i].appendChild(newCell2); + } +}); + +const removeRow = document.getElementById("remove-row"); + +removeRow.addEventListener("click", () => +{ + const nmberOfRows = document.getElementsByTagName("TR").length; + const lastRow = document.getElementsByTagName("TR")[nmberOfRows - 1]; + lastRow.remove(); +}); + +const removeColunm = document.getElementById("remove-column"); + +removeColunm.addEventListener("click", () => +{ + const nmberOfRows = document.getElementsByTagName("TR").length; + + for (let i = 0; i < nmberOfRows; i++) + { + const removeCell = document.getElementsByTagName("TR")[i]; + removeCell.lastElementChild.remove(); + } +}); + +const currentColor = document.getElementById("color-select"); + +const colorCell = document.getElementsByTagName("table")[0]; + +colorCell.addEventListener("click", (event) => { - addRow.addEventListener("click", () => + if (event.target.tagName === "TD") { - + event.target.style.backgroundColor = currentColor.value; + } +}); + +const fillUncoloredCells = document.getElementById("fill-uncolored-cells"); + +fillUncoloredCells.addEventListener("click", () => +{ + const cells = document.getElementsByTagName("TD").length; + + for (let i = 0; i < cells; i++) + { + const currentCell = document.getElementsByTagName("TD")[i]; + if (!currentCell.style.backgroundColor) + { + currentCell.style.backgroundColor = currentColor.value + } + } +}); +const fillAllCells = document.getElementById("fill-grid"); - }); +fillAllCells.addEventListener("click", () => +{ + const cells = document.getElementsByTagName("TD").length; + + for (let i = 0; i < cells; i++) + { + const currentCell = document.getElementsByTagName("TD")[i]; + currentCell.style.backgroundColor = currentColor.value + } +}); +const clearAllCells = document.getElementById("clear-grid"); +clearAllCells.addEventListener("click", () => +{ + const cells = document.getElementsByTagName("TD").length; -} \ No newline at end of file + for (let i = 0; i < cells; i++) + { + const currentCell = document.getElementsByTagName("TD")[i]; + currentCell.style.backgroundColor = ""; + } +}); + +let isMouseButtonDown = false; + +document.addEventListener("mousedown", () => +{ + isMouseButtonDown = true; +}); + +document.addEventListener("mouseup", () => +{ + isMouseButtonDown = false; +}); + +document.addEventListener("mouseover", (event) => +{ + if (isMouseButtonDown && event.target.tagName === "TD") + { + event.target.style.backgroundColor = currentColor.value; + } +}); \ No newline at end of file From 9b9a128aa1cfa65551b6155039188ac1a0247197 Mon Sep 17 00:00:00 2001 From: Muhammad Date: Fri, 20 Jun 2025 20:26:31 -0400 Subject: [PATCH 4/4] final-commit --- index.html | 2 ++ main.js | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 1a138b6..9ec2189 100644 --- a/index.html +++ b/index.html @@ -31,8 +31,10 @@

Grid Maker

+ +