Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
john larson
16,594 Pointstrying to break this code down to bite size chunks, bit its not working...
I was hoping this would create some elements on the page...
var body = document.getElementByTagName("body")
var ul = document.createElement("ul");
var li = document.createElement("li");
body.appendChild(ul);
ul.appendChild(li);
Am I way off or is it something simple that I missed?
1 Answer
dbrink dbrink
6,258 PointsWhen running your code, I got
"Uncaught TypeError: document.getElementByTagName is not a function".
Try removing the body variable and using
document.body.appendChild(ul);
directly. This did the trick for me.
john larson
16,594 Pointsjohn larson
16,594 PointsYes, that certainly did the trick...how did you know to try that? It looked to me that mine followed the same kind of logic as yours, but yours worked and mine didn't. Is there some rule in this circumstance that I'm just not aware of yet?
dbrink dbrink
6,258 Pointsdbrink dbrink
6,258 PointsI'm not certain of any rules (still very much learning the DOM), but I had just never seen body attached to a variable before and it didn't seem like there was anything else that it could be.
john larson
16,594 Pointsjohn larson
16,594 PointsOK, I need your way of thinking I guess :D