Just a Title explainer

The aim of this puzzle: Use JS to add a title to a webpage using an h1 element.

Walkthrough of the solution: In the JS tab, create a variable named title. This will be used to store the new h1 element. To create an h1 element, you use the document.createElement() method. The argument of the method is a string which will be the tag of your new element. For this puzzle, we want to use let title = document.createElement('h1').

Next, we need to give the element some text, otherwise it’s just blank. To set the text of the element we assign a string to its .textContent. The element is stored in the title variable, so we can use title.textContent = 'Adoptable Animals'.

Now, the h1 element is ready and stored in the title variable, but it still needs to be added to the page. To do that, you append the element to the body using body.appendChild(title). Remember that we are storing document.body in the variable named body, so this is the same as document.body.appendChild(title).

JavaScript Concepts: .textContent, .createElement(), document, body, .appendChild()

HTML Concepts: h1