0
Hello could you please help me? It says it cannot read line 11. But I can't figure it out why...
3 Answers
+ 2
The issue is not with the code. The problem is JS code is loading before the HTML code. If you order the JS in body tag, it will work -
<!DOCTYPE html>
<html>
<head>
<title>Chain reaction</title>
<meta charset="utf-8" />
</head>
<body>
<table></table>
<script>
var table = document.querySelector("table");
for (var i=0; i<6; i++) {
var row=document.createElement("tr");
for (var j=0; j<6; j++) {
var cell=document.createElement("td");
row.appendChild(cell);
}
table.appendChild(row);
}
document.addEventListener ("click", function (e) {
var node=e.target;
if (node.nodeName =="TD") {update (node)};
});
var update=function (cell){
cell.innerHTML += "o";
}
</script>
</body>
</html>
+ 1
Sachin, thank you very much! Is there any way I can keep my JS HTML and CSS separated as they are? How could I link it to each other here in sololearn? (I can't see the folders here so I cannot figure out the path....)
+ 1
CSS can be separated and JS too. The only thing you need to take care in JS section is not to put any code which loads before the HTML.