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

App not working after Refactoring- not sure why?

I watched the video twice and did exactly what it showed me to do. My app was working perfectly before the refactoring and is now completely broken. Please help me understand what went wrong?

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

    function appendToLi(elementName, property, value){
        const element = createElement(elementName, property, value);
        return element;
    const li = document.createElement('li');

    appendToLi('span', 'textConent', text);                     
    appendToLi('label', 'textContent', 'Confirmed')
        .appendChild(createElement('input', 'type', 'checkbox'));       
    appendToLi('button', 'textContent', 'Edit');        
    appendToLi('button', 'textContent', 'Remove');  
    return li;

2 Answers

Swan The Human
Swan The Human
Full Stack JavaScript Techdegree Student 19,326 Points

Have you double checked to make sure your script tag linking the js to the html is back at the bottom of the html? If not youll have to make sure your entire code is wrapped with the DOMContentLoaded event handler

can you give the link to your workspace?