I have an assignment at my school to write the DOM of the webpage when JavaScript has executed. We got the assignment on paper and when I tried to write it on sublime and run it the code won't work. I think the problem is at the following lines:
tdTextNodeRef=document.createTextNode(codeNodeRefs[counter].innerHTML);
tdNodeRef.appendChild(tdTextNodeRef);
The full code can be found here: https://github.com/Nirakander/JS-assignment
Why won't this work? Really bad assignment when the code is not even working. Thanks in advance!
Your error is here:
That extra semicolon ends the if statement with an empty block, the following block is seen as just a block of statements. So it loops around twice, does nothing, then goes into the block.
When entering that block, count is codeNodeRefs.length (i.e. 2), so codeNodeRefs[counter] returns undefined.
Just remove the semicolon.