Skip to content
Open
Changes from all commits
Commits
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
41 changes: 41 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,48 @@


// Please feel free to change the JS as you see fit! This is just a starting point.

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




// Get elements using getElementById
const table = document.getElementsByTagName("table")[0];
const colorSelect = document.getElementById("color-select");
const fillGridBtn = document.getElementById("fill-grid");


let currentColor = colorSelect.value;

//Asmaa: Select a color from a dropdown menu
colorSelect.addEventListener("change", function (event) {
currentColor = event.target.value;
});

//Asmaa: Click a cell to change its color to the selected color
table.addEventListener("click", function (event) {
if (event.target.tagName === "TD") {
event.target.style.backgroundColor = currentColor;
}
});

//Asmaa: Fill uncolored cells with the selected color
fillGridBtn.addEventListener("click", function () {
const rows = table.getElementsByTagName("tr");
for (let i = 0; i < rows.length; i++) {
const cells = rows[i].getElementsByTagName("td");
for (let j = 0; j < cells.length; j++) {
if (!cells[j].style.backgroundColor) {
cells[j].style.backgroundColor = currentColor;
}
}
}
});