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 Loops, Arrays and Objects Tracking Multiple Items with Arrays Adding Data to Arrays

playlist.push printing above <h1>

var playList = []; playList.push("this is test"); playList.push("test" +"test" ); printList(playList);

Joseph Fraley
Joseph Fraley
Treehouse Guest Teacher

It's very difficult to debug code in a vacuum. If you provide the forum with your entire relevant code block, that will dramatically improve your odds of getting a helpful answer!

In fact, you can use this nifty trick to make it EVEN easier for people in the forum to help:

You can include blocks of code in a comment by typing

```nameOfCodeLanguage
{block of code}
```

For example:

```javascript
var example = "isn't this easy to read?";
console.log(example); // => "isn't this easy to read?"
```

Looks like this:

var example = "isn't this easy to read?";
console.log(example); // => "isn't this easy to read?"

If you find this helpful, please up-vote my answer as "Best Answer"! It helps me reach my career path goals quickly. If not, feel free to write more!

3 Answers

hey , tried working on it again and its not working at all . heres a print out if anyone has any advice.

https://w.trhou.se/mv2io8kmll

Joseph Fraley
STAFF
Joseph Fraley
Treehouse Guest Teacher

There are a number of problems with the code in the link. Your first step should be to get very comfortable using javascript console.log() to figure out what your code is doing, as opposed to what you think it should be doing.

For example:

function printList( list ) {
  var listHTML = '<ol>';
  for (var i = 0; i < list.length; i += 1) {
    listHTML += '<li>' + list[i] + '</li>';
  }
  listHTML += '</ol>';
  print(listHTML);
}

what does line 7 in helpers.js do? is print() a function that you've defined somewhere above? Not sure?? Try console.log( print ) and see if it returns a function. print(listHTML) is being passed an argument of listHTML. What does that look like at this point in the code? Does it look like you think it does? add a statement before hand: console.log(listHTML); and see what it returns.

How about line 3 in playlist.js? is print.List() the function that you think it is? It is dangerously close to function printList() as defined on line 1 of helpers.js

As far as I can tell, that should put you on a direct path to debugging your problems. When I work out those issues, your code runs as expected.

! If you find this helpful, please up-vote my answer as "Best Answer"! It helps me reach my career path goals quickly. If not, feel free to write more!

Jose Vaides
Jose Vaides
18,136 Points

You're getting the list printed above the h1 because in the index.html file, you included the script tag both inside the head and the body of your file. Therefore the scripts run two times, and one of them is before your file's body, which is why it appears above the h1