0

Hello could you please help me? It says it cannot read line 11. But I can't figure it out why...

https://code.sololearn.com/WkpX2K75O35Q/?ref=app

25th Dec 2019, 7:50 AM
Jana Vrzalova
Jana Vrzalova - avatar
3 Respuestas
+ 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>
25th Dec 2019, 8:14 AM
Sachin Artani
Sachin Artani - avatar
+ 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....)
25th Dec 2019, 9:34 AM
Jana Vrzalova
Jana Vrzalova - avatar
+ 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.
25th Dec 2019, 2:53 PM
Sachin Artani
Sachin Artani - avatar