For #1, the script is working as expected and a new line is being added. The only problem is that HTML doesn't render new line characters in the source code (which is what
document.writeln is writing) on the screen. If you want to see a new line, you want to use a
<br> tag or wrap text in a block element like
<p> which spaces out text blocks. If you look at the generated code in that sample (most browsers should let you do this using right-click > inspect) you should be able to see your
Hello again, John!
For #2, the problem is that there's a difference between elements and nodes in the DOM. Elements are tags, or anything that is wrapped in
>. Nodes are elements and everything else, including text that's not in tags. Consider the nodes in this example
Here there are 3 child nodes, the text node "Hello," (not including the white space), the bold
<b> element containing "world" and another text node for the "!". Of these child nodes, there's only one element child, the bold element.
children refers to elements and
childNodes refers to all children (nodes). Similarly,
firstChild targets child nodes while
firstElementChild targets elements. First you used
children which is (correctly) getting the first element child and reporting its tagName. However following that you;re using
firstChild which is picking up the first child node which is not an element, but rather a text node, which, not being an element does not have a
tagName, so it comes back
Granted, these have odd names and it can be confusing. I think the problem is largely simply from the fact that some of these APIs came out before the others where the naming was already a little confuddled and having functional parity just meant it had to be a little weird like this (like why isn't it children for nodes and elementChildren for elements?).