The code below is supposed to add a p element to my document, add text to this element, and change the font color of the element to red.
This is for a class. I have been working on this for two hours but am stumped.
<!DOCTYPE html>
<html>
<body>
<h1 id='demo'>
THE TITLE OF YOUR WEBPAGE
</h1>
<div id="container">
<div class="content">
This is the glorious text-content!
</div>
</div>
</body>
<script>
const p = document.createElement('p');
p.textContent = 'Hey, I'm red.';
p.style.color = 'red';
div.content.appendChild('p');
</script>
</html>
The code doesn't produce the desired results. Can any of you help me understand what I am missing?
"Hey I'm red.", using double quotes instead. Also,divis not defined. Your code has no idea whatdivis. You'll need to tell it that you want an element on the page by doing something likedocument.getElementById("container").