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 Breaking on DOM Changes and Watch Expressions

Need help with this bug...

Submitting new names to the list results in guests named "span" rather than the name submitted. Also, the new list item's children all have the wrong names.

I know the problem is in this function...

function createLI(text) { function createElement(elementName, property, value) { const element = document.createElement(elementName); element[property] = elementName; return element; }

function appendToLI(elementName, property, value) {
  const element = createElement(elementName, property, value);
  li.appendChild(element);
  return element;
}

const li = document.createElement("li");
appendToLI("span", "textContent", text);
appendToLI("label", "textContent", "Confirmed").appendChild(
  createElement("input", "type", "checkbox")
);
appendToLI("button", "textContent", text);
appendToLI("button", "textContent", "remove");
return li;

}

In the function createElement my text editor is telling me that value is declared but never read.

Also I don't know what the line - element[property] = elementName; - is or what it does.

Any help is greatly appreciated, if you've figured it out I'd be happy if you posted the correction so I could look at it.

1 Answer

Steven Parker
Steven Parker
231,269 Points

You've identified the line causing the problem, and the fact that "value" is not being used.

So instead of "element[property] = elementName;" it should be "element[property] = value;".