Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
aae4c91
rows added - resolves 1
haicomet Jun 20, 2025
63a687e
Merge pull request #11 from haicomet/add-rows
haicomet Jun 20, 2025
24c7e8d
rows can now be removed
jeramyleon Jun 20, 2025
2880693
column btn added - resolves 2
haicomet Jun 20, 2025
057b507
Merge pull request #12 from haicomet/add-columns
haicomet Jun 20, 2025
1a692e5
Added script.js with the fillUnclrdCells function
BTBurton1 Jun 20, 2025
4a7caf3
Added fillEveryCell function
BTBurton1 Jun 20, 2025
5f9ab39
Updated script.js gave it the event listener code
BTBurton1 Jun 20, 2025
c0aac7c
Update script.js added its event listener code
BTBurton1 Jun 20, 2025
8ce81f7
Deleted script.js so it doesnt conflict with main.js
BTBurton1 Jun 20, 2025
7cca281
Updated main.js to have the fillunclrdcells function
BTBurton1 Jun 20, 2025
dad3a64
deleted script.js so it doesnt conflict with the main.js
BTBurton1 Jun 20, 2025
6b548a6
clear grid - resolves 9
haicomet Jun 20, 2025
1dd8cdb
Updated main.js to have the fillEveryCell function
BTBurton1 Jun 20, 2025
b2eca0b
Merge pull request #13 from haicomet/clear-all-cells
haicomet Jun 20, 2025
461295b
added feature to remove columns
jeramyleon Jun 20, 2025
633a362
Complete task 6: color cell on click
Jun 20, 2025
efae2c4
merging
jeramyleon Jun 20, 2025
24e8d34
Merge pull request #14 from haicomet/remove-rows-from-grid
jeramyleon Jun 20, 2025
b8635f7
Complete task 6: color cell on click
Jun 20, 2025
23e92c7
select a color from a dropdown menu of colors
Jun 20, 2025
4bb9103
Merge pull request #16 from haicomet/fill-unclrd-cells
BTBurton1 Jun 20, 2025
942ad13
click on a single cell, changing its color to the currently selected …
Jun 20, 2025
bd403ac
merging remove-columns
jeramyleon Jun 20, 2025
b582328
Merge branch 'main' into task-5
BenjaminA-cs-hub Jun 20, 2025
9a3ef66
Merge pull request #18 from haicomet/task-5
BenjaminA-cs-hub Jun 20, 2025
e5b74e6
Merge branch 'main' into task-6
BenjaminA-cs-hub Jun 20, 2025
d4bb474
Merge pull request #19 from haicomet/task-6
BenjaminA-cs-hub Jun 20, 2025
d8e95b6
Update main.js
BenjaminA-cs-hub Jun 20, 2025
802bfce
Merge branch 'main' into fill-every-cell
Jun 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div id="root">
<h1>Grid Maker</h1>
<table>
<tbody>
<tbody id="tableBody">
<tr>
<td></td>
<td></td>
Expand All @@ -33,12 +33,19 @@ <h1>Grid Maker</h1>
<div>
<button id="add-row">Add Row</button>
<button id="add-column">Add Column</button>
<button id="remove-row">Remove Row</button>

<select id="color-select">
<option value="red">Red</option>
<option value="blue">Blue</option>
</select>
<button id="fill-grid">Fill Grid</button>
<button id="clear-grid">Clear Grid</button>
<<<<<<< HEAD
<button id="remove-row">Remove Row</button>
=======
<button id="remove-column">Remove Column</button>
>>>>>>> remove-columns-from-the-grid
</div>
</div>
</body>
Expand Down
107 changes: 107 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,114 @@
// Please feel free to change the JS as you see fit! This is just a starting point.

function removeRow() {
const tableBody = document.getElementById("tableBody");

try {
tableBody.deleteRow(0);
} catch (error) {
console.error("No more rows to delete", error.message);
}
}

const removeRowButton = document.getElementById("remove-row");
removeRowButton.addEventListener("click", removeRow);

const root = document.getElementById("root");
root.addEventListener("click", (event) => {
console.log(event.target.tagName);
console.log(event.target);
});

// Task 5 - Color Dropdown Logic
const colorSelection = document.getElementById("color-select");
let colorChoice = colorSelection.value;

colorSelection.addEventListener("change", function () {
colorChoice = colorSelection.value;
console.log("User selected:", colorChoice);
});

// Task 6 - Click Cell to Color It
const cells = document.querySelectorAll("td");

cells.forEach((cell) => {
cell.addEventListener("click", () => {
const selectedColor = colorSelection.value;
cell.style.backgroundColor = selectedColor;
});
});

let table = document.querySelector("TABLE");
const addRowBtn = document.getElementById("add-row");
const addColBtn = document.getElementById("add-column");
const clrBtn = document.getElementById("clear-grid");
let rows = document.getElementsByTagName("TR");
let tdCount = rows[0].querySelectorAll("TD").length;

addRowBtn.addEventListener("click", () => {
let newRow = document.createElement("TR");

for (let i = 0; i < tdCount; i++)
newRow.appendChild(document.createElement("TD"));

table.appendChild(newRow);
});

function fillUnclrdCells() {
console.log("🟡 fillUnclrdCells triggered");
const cells = document.querySelectorAll("td");
const selectedClr = document.getElementById("colorSelector").value;

cells.forEach((cell) => {
if (!cell.style.backgroundColor || cell.style.backgroundColor === "white") {
cell.style.backgroundColor = selectedClr;
}
});
}

document.getElementById("fill-grid").addEventListener("click", fillUnclrdCells);

addColBtn.addEventListener("click", () => {
Array.from(rows).forEach((element) => {
let newCol = document.createElement("TD");
element.appendChild(newCol);
});

tdCount += 1;
});

clrBtn.addEventListener("click", () => {
const cells = document.getElementsByTagName("TD");
Array.from(cells).forEach((cell) => (cell.style.backgroundColor = "white"));
});

function removeColumn() {
const tableBody = document.getElementById("tableBody");

try {
const rows = tableBody.rows;

for (let i = 0; i < rows.length; i++) {
const row = rows[i];
row.deleteCell(0);
}
} catch (error) {
console.error("No more columns to delete", error.message);
}
}

const removeColumnButton = document.getElementById("remove-column");
removeColumnButton.addEventListener("click", removeColumn);

function fillEveryCell() {
console.log("🟡 fillEveryCell triggered");
const cells = document.querySelectorAll("td");
const selectedClr = document.getElementById("colorSelector").value;

cells.forEach((cell) => {
cell.style.backgroundColor = selectedClr;
});
}
document
.getElementById("fill-uncolored")
.addEventListener("click", fillEveryCell);