I am in on a course on Udacity and we have to make a project, which is easy to do but I’ve been practicing on it with different stuff and trying to do it both in jquery and without.
Now I stuck at a point not really understanding this part. Whether this is even a possible way to finish what I started or did I just had to abandon this and do it other way.
Take a look please! convo on forums: https://imgur.com/a/AFW2z
https://codepen.io/adkuca/pen/JMJEBZ/
then I tried this and found it counts weird, is this even doable?
function cellColorCheck() {
var x = 0;
for (let i = 0; i < pCanvas.getElementsByTagName('td').length; i++) {
if (pCanvas.getElementsByTagName('td')[i].style.backgroundColor != "") {
x++;
//console.log(pCanvas.getElementsByTagName('td')[i].style.backgroundColor)
}
console.log(x);
/*while (pCanvas.getElementsByTagName('td')[i].style.backgroundColor == "") {
btn1.disabled = true;
}*/
//console.log(pCanvas.getElementsByTagName('td')[i].style.backgroundColor);
}
}
function cellClickAddColor (cell) {
cell.addEventListener('mousedown', function(evt) {
if (evt.button == 0) {
this.style.backgroundColor = colorPicker.value;
//console.log(this.style.backgroundColor); //broji po jedan
/*btn1.disabled = false;*/
} else if (evt.button = 2) {
this.style.backgroundColor = "";
}
cellColorCheck()
//console.log(pCanvas.getElementsByTagName('td')[23].style.backgroundColor);
})
}
function makeGrid() {
for (let i = 0; i < pHeight.value; i++) {
const row = pCanvas.insertRow(i);
for (let j = 0; j < pWidth.value; j++) {
const cell = row.insertCell(j);
cellClickAddColor(cell);
cellClear(cell);
cellHoverAddColor(cell);
//cellColorCheck(cell);
}
}
}
Thanks!