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 trialn r
7,665 Points"items is not defined at createListItems"
This is my code:
function createListItems(arr) {
let items = '';
for ( let i = 0; i < arr.length; i++) {
items += <li>${ arr[i] }</li>
;
}
return items;
}
I've looked over it multiple times, re-written it, copied it from the video and it's still telling me that items is undefined in the console when I try to call playlist. I hope it's not just a simple syntax error that I am overlooking.
1 Answer
Bella Bradbury
Front End Web Development Techdegree Graduate 32,790 PointsHello!
The bad news, it is just a little syntax error. The good news, it's very easy to fix and the rest of your code looks great!
Your code above doesn't have the template literal (aka <li>${ arr[i] }</li>
) surrounded by backticks. Backticks (`) are usually sharing the key with the tilde (~) in the top left of the keyboard. Your complete code should look like this:
function createListItems(arr) {
let items = '';
for ( let i = 0; i < arr.length; i++) {
// backticks(`) marked in code below with asterisks(*)
// * *
items += `<li>${ arr[i] }</li>`;
}
return items;
}
Hope this helps!