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

.a{fill-rule:evenodd;}techdegree seal-36
Front End Web Development Techdegree Graduate 23,907 Points

Parameter as string

In the createElement function, for span, text is passed NOT as a string, but when calling the function for others(checkbox and others), the value is passed as string. why doe the code work for span when it is not passed as a string

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


const span = createElement('span','textContent', text);

const checkbox = createElement('input','type','checkbox');

1 Answer

Leonard Crantford
Leonard Crantford
Full Stack JavaScript Techdegree Student 12,190 Points

Hello Olubukola, I believe the answer to your question is in the case text is not passed as a string it is passing the value of the variable named string. For me the workshop I believe you are asking about was both enlightening and confusing as some of the variables and passed values looked the same, therefore making it easy to loose cohesion in following the trail of passed parameters. It helped me to trace the calls a few times before I could feel confident of the map it represented. I hope this helps, lbc