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

How to create a paragraph element and assign it to the newParagraph variable.

Create a paragraph element and assign it to the newParagraph variable.

app.js
var contentDiv = document.getElementById('content');
var p = document.querySelector('.newParagraph');
index.html
<!DOCTYPE html>
<html>
    <head>
        <title>DOM Manipulation</title>
    </head>
    <link rel="stylesheet" href="style.css" />
    <body>
        <div id="content">
          <p class="newParagraph"></p>
        </div>
        <script src="app.js"></script>
    </body>
</html>

2 Answers

Hey! We meet again. You probably already got it figured by now but just in case...... It seems you're missing the variable declaration for newParagraph, so add that first. Once thats done, the challenge is asking to create a new paragraph (<p>) html element using javascript, so the createElement() method would need to be used on the document object in order to do this and add an argument of "p" for the paragraph element to be created. then we would store that in the newParagraph variable. So it should look like this:

var contentDiv = document.getElementById('content');

var newParagraph;

newParagraph = document.createElement("p");

Thanks so much Xavier Ritch. ;)

Thank you, God bless you.

Blake Larson
Blake Larson
13,014 Points

They want you to create it with javascript. You are grabbing from the DOM because it already exists.

var newParagraph = document.createElement("P");

Thanks so much. ;)

Should the ("P") be lowercase like this ("p") or does it matter?