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

JavaScript JavaScript and the DOM (Retiring) Making Changes to the DOM DOM Manipulation

Append the newParagraph element to the content DIV element

I appended the child element and it doesnt seem to pass what am I doing wrong?

app.js
const contentDiv = document.getElementById("content");
let newParagraph=document.createElement('p');
newParagraph.className='panel';
contentDiv.appendChild('newParagraph')[0];
index.html
<!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>
Janina Diers
Janina Diers
1,276 Points

Hi. In your app.js file is one little mistake. On line 4 you are passing newParagraph as a string instead of a variable in your appendChild function. This should work:

contentDiv.appendChild(newParagraph);

1 Answer

Collin Halliday
seal-mask
.a{fill-rule:evenodd;}techdegree
Collin Halliday
Full Stack JavaScript Techdegree Student 17,491 Points

Hey, Adam.

You don't need to put the variable name newParagraph in quotes. Otherwise, you are essentially attempting to append the string 'newParagraph' to the contentDiv. The appendChild() method wants an element to append as the last child of another element, in this case, the contentDiv. If you remove the quotes, your code should run just fine.

Also, you do not need the [0] in your code, as you are not dealing with pinpointing a particular element out of a collection or array.

I hope that helps. Best of luck.

Thank You I understand I was appending a string with the quote marks this helps.