Having difficulties with an MDN active learning section

Hello everyone! Welcome to my first topic :sunglasses:

I’ve been stuck on the active learning section of this MDN article in Fundamentals part-4. I made it a point to do everything the course asks and would rather not skip anything, especially this early.

Both exercises require using a set of code that I dont recall learning earlier in the course and the article itself doesnt really explain it beforehand, so I am unsure how to apply them to their respective loops. I would like a little help to understand how this code is suposed to be used. Many thanks in advanced!

Hi, can you post the the code and show the problematic section. Myabe i could help.

1 Like

Hi :wave: its the two active learning sections near the bottom of the page.

The first one has this code

output = document.querySelector(’.output’);
const para = document.createElement(‘p’);
output.appendChild(para);
para.textContent =

The second exercise im not too sure about the terms either.

Yes, you are rigth these lines are explained in the next part DOM manipulation

This allows you to acces and modify the html elements from javascript.

 output = document.querySelector(’.output’);

Select the html element with id=“ouput” and save in the variable output.

 const para = document.createElement(‘p’);

creates a <p></p> element and save it in the variable para

 output.appendChild(para);

put the para element as child of output.

 para.textContent = "something"

sets the text content of the p element with “somethin”

After runing this you end with “somethin” showing in the html as a content of a p element inside the html elemet with id=“output”

Hope this will help.

1 Like

Ohhh I see, why did they stucture it like that? Thanks for your explanations btw! I’ll put them to good use :muscle: :brain: