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 trialBoonsuen Oh
18,788 PointsJS & DOM coding challenge
Anyone help me out? Stuck at Task 2.
const contentDiv = document.getElementById("content");
let newParagraph = document.createElement('p');
panel.className = 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>
Boonsuen Oh
18,788 PointsThanks Sergi I've tried newParagraph.className = "panel"; It works!
2 Answers
Steven Parker
231,271 PointsThe instructions for task 2 are worded awkwardly.
And it looks like you tried to follow them a bit too literally, while confusing the class name with an element.
The instructions say "Set the class of panel to the newParagraph.", but imagine if they said one of these instead:
- Give the class of "panel" to the newParagraph
- Set the class of
panel
on the newParagraph
I'd bet you would have gotten it on the first try with either of these.
Boonsuen Oh
18,788 PointsYeah that is confusing...
Bridger Hammond
Front End Web Development Techdegree Graduate 14,156 PointsThis. So much this. I had to read the sentence like 4 times and still wasn't sure if that's what they wanted.
Gonzalo Blasco
11,927 PointsnewParagraph.className = "panel";
Sergi Oca
7,981 PointsSergi Oca
7,981 PointsI haven't took that course and I'm not sure if that's what you were supposed to learn, but for me it passed with:
newParagraph.className ="panel";
It also passes with:
newParagraph.classList.add("panel");
element.classList allow you to remove a class (element.classList.remove("foo")). To add a class (element.classList.add("bar")). Or to check if an element contains a class (element.classList.contains("aClass")).
What you were trying to do with "panel.className = newParagraph;" is to assing a className to panel, which is not defined as a variable anywhere, and then you tried to give it a className of newParagraph, which is a defined variable. You cannot assign a variable as a className (that I am aware), a className has to be a string.