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 JavaScript Arrays Loop Through Arrays Loop Through an Array

Jelena Feliciano
seal-mask
.a{fill-rule:evenodd;}techdegree
Jelena Feliciano
Full Stack JavaScript Techdegree Student 12,729 Points

Trying to understand why nothing is showing on the console like the teachers example.

const playlist = [ 'So What', 'Respect', 'What a Wonderful World', 'At Last', 'Three Little Birds', 'The Way You Look Tonight' ];

function createListItems (arr) {

}

this is copied from the video but when the teacher goes in to the console it shows the list. For me nothing appears. I added the console.log to see if that would give me something but it only shows the elements in the array. not the list the way the teachers example shows. what am i doing wrong?

2 Answers

cazepeda
cazepeda
6,099 Points

I think you jumped ahead? I believe he was showing the example of what he was going to do with the JavaScript. Then after showing you the example he was going to start writing the loop to generate the <li> items.

Below is what he eventually completes in order to generate the <li>'s.

const playlist = ['So What', 'Respect', 'What a Wonderful World', 'At Last', 'Three Little .Birds', 'The Way You Look Tonight'];

function createListItems(arr) {
    let items = ''; // empty variable.
    for (let i = 0; i < arr.length; i++) { // start loop to add to the items variable and create the list.
        items += `<li>${ arr[i] }</li>`;
    }
    return items;
}

createListItems(playlist); // run the function above.

Hi Jelena,

I'm sure you already got this resolved since it was so long ago, but just my 2 cents for anyone who may experience this in the future. You might want to make sure that you have the correct .js file added to your index.html. I made this mistake a few times. It's pretty frustrating since there is no error to point you in the right direction.

Hope that helps you or someone in the future :)! Happy coding!