Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Nicholas Wallen12,278 Points
This was never explained....
IF the answer to task three is:
Is someone going to bother explaining how we came up with contentDiv versus just div? No where in this course was it explained how we can randomly mash those two words together.
const contentDiv = document.getElementById("content"); let newParagraph = document.createElement('p'); newParagraph.className = "panel"; contentDiv.appendChild(newParagraph);
<!DOCTYPE html> <html> <head> <title>DOM Manipulation</title> </head> <link rel="stylesheet" href="style.css" /> <body> <div id="content"> </div> <script src="app.js"></script> </body> </html>
Eric M11,517 Points
contentDiv is a variable. The
const keyword is similar to the
var keywords with the difference being the contents of the variable cannot be mutated. It has to stay constant.
const contentDiv = document.getElementById("content"); and
let newParagraph = document.createElement('p'); both declare variables. The first named contentDiv, which cannot change, and the second
newParagraph which can change.
So, contentDiv is just so we can easily reference
document.getElementById("content") without having to type all of that out each time.
If you're ever unsure about something, consider looking up each part of the line you're unsure of in the MDN, it's a great resource! Or rewatch the Treehouse videos. I find myself rewatching them at various times, the speedup feature and transcripts are great for reviewing things you've already covered.