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 One Solution

Siddharth Pande
Siddharth Pande
9,046 Points

Review my Code Please

// 1: Set the text of the <h1> element
var h1 = document.getElementsByTagName('h1')[0];
h1.textContent = "Practice Session Win";

// 2: Set the color of the <h1> to a different color
h1.style.color = 'red';

// 3: Set the content of the '.desc' paragraph
// The content should include at least one HTML tag
var desc = document.getElementsByClassName('desc')[0];
desc.innerHTML= '<h4>Hello Jlo</h4>';

// 4: Set the class of the <ul> to 'list'
var ul = document.getElementsByTagName('ul')[0];
ul.className = "list";

// 5: Create a new list item and add it to the <ul>
var newListItem = document.createElement('li');
newListItem.innerHTML = '<input>The New List Item';
ul.appendChild(newListItem);

// 6: Change all <input> elements from text fields to checkboxes
var allInput = document.querySelectorAll('input');
allInput.forEach(function (elem,index) {
elem.type = "checkbox"});

// 7: Create a <button> element, and set its text to 'Delete'
// Add the <button> inside the '.extra' <div>
var delBtn = document.createElement('button');
delBtn.textContent = 'Delete';
var extraDiv = document.getElementsByClassName('extra')[0];
extraDiv.appendChild(delBtn);

// 8: Remove the '.extra' <div> element from the DOM when a user clicks the 'Delete' button
delBtn.addEventListener('click', () => {
  extraDiv.parentNode.removeChild(extraDiv);
});

1 Answer

Steven Parker
Steven Parker
231,261 Points

Looks like you nailed it. :+1: I think you might be ready to "fly solo" on these.

Siddharth Pande
Siddharth Pande
9,046 Points

Wow! Thanks for the thumbs up. This is really a confidence booster for me.