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

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
seal-mask
.a{fill-rule:evenodd;}techdegree
Leonard Crantford
Full Stack JavaScript Techdegree Student 13,269 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