Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript DOM Scripting By Example Improving the Application Code Refactor 1: Create List Items

Nnanna Okoli
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Nnanna Okoli
Front End Web Development Techdegree Graduate 19,167 Points

App not working ..

app.js:59 Uncaught ReferenceError: element is not defined at appendToLI (app.js:59:24) at createLI (app.js:66:3) at HTMLDocument.<anonymous> (app.js:87:14)

Please could you help me understand what the error is here, as I understand the purpose of this task is DRY. But I'm quite confused by this tutorial and struggle to resolve the error.

Thank you in advance, please see the link below. https://w.trhou.se/vdf5jafczn

1 Answer

The reference error means that Javascript can't find the variable named element.

    function appendToLI(elementName, property, value) {
        const span = createElement(elementName, property, value);
        // to add the text to the list element
        li.appendChild(element);
        return element;

    }

In the first line of the function, the variable span was created. In the lines after the comment, the variable element is used instead. Try changing span to element or element to span so that all three lines of code use the same name for the variable.