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 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);
        li.appendChild(element);
        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
seal-mask
.a{fill-rule:evenodd;}techdegree
Swan The Human
Full Stack JavaScript Techdegree Student 19,338 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?