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 Data Using Objects The Build an Object Challenge, Part 2

Parker Brown
Parker Brown
24,308 Points

Code will not show up in Browser, using Firefox

Here is my report.js file:

var message = ' ';
var student;

function print(message) {
  var outputDiv = document.getElementById('output');
  outputDiv.innerHTML = message;
}

for (var i = 0; i < students.length; i += 1) {
  student = students[i];
  message += '<h2>Name: ' + student.name + '<h2>';
  message += '<p>Track: ' + student.track + '<p>';
  message += '<p>Achievements: ' + student.achievements + '<p>';
  message += '<p>Points: ' + student.points + '<p>';
}
print(message);
jack AM
jack AM
2,618 Points

Can you show where students is being defined for us?

4 Answers

Parker Brown
Parker Brown
24,308 Points

Got It Running! I had to close out of WorkSpaces and open a new one.

jack AM
jack AM
2,618 Points

Glad it worked out!

jack AM
jack AM
2,618 Points

Okay I gotcha. I just went to your workspace, and as soon as I included

<script src="js/report.js"></script>

Your code worked just fine.

Parker Brown
Parker Brown
24,308 Points

jack AM thanks for the response I went back in and found my html file did have both students.js and report.js included in it. Still no dice on getting it to display in my browser, which is Firefox.

jack AM
jack AM
2,618 Points

On the off chance, have you tried clearing the cache? Windows : control+F5, osx: command+r

Parker Brown
Parker Brown
24,308 Points

I actually had not cleared my cache, but just did. Still no dice.

Matt F.
Matt F.
9,518 Points

Hi Parker,

If this is your entire JavaScript file, it will result in an error, as the variable students is not defined.

Since your for loop will run for each item in students, it will not run at all when students is undefined.

It should work if you define students as an array like this:

var message = ' ';
var student;

var students = [
  {
    name: "Larry",
    track: "front end",
    points: 700
  },
  {
    name: "Curly",
    track: "design",
    points: 700
  }
]

function print(message) {
  var outputDiv = document.getElementById('output');
  outputDiv.innerHTML = message;
}

for (var i = 0; i < students.length; i += 1) {
  student = students[i];
  message += '<h2>Name: ' + student.name + '<h2>';
  message += '<p>Track: ' + student.track + '<p>';
  message += '<p>Achievements: ' + student.achievements + '<p>';
  message += '<p>Points: ' + student.points + '<p>';
}
print(message);
Parker Brown
Parker Brown
24,308 Points

Matt F. thanks for the response however, I gathered from the prior video that we were to link both js files together in the html doc. I did that and got no code displaying in browser. So I followed your advice and combined all the data into one js file, then reran it and still got no code displaying. I'm wondering if I have a browser issue or is Workspaces has issues with Firefox?

Matt F.
Matt F.
9,518 Points

Hi Parker,

Two ideas would be:

1.) Use Chrome and see if the problem goes away there. If the same problem exists in Chrome, then it is not a browser issue.

2.) Take your HTML and JS and put it into Codepen or JSBin and see if it works there

If both of these tield the same results, it is almost certainly the code itself. If that is the case, please post your HTML and JS here and I will take a look at it.

Parker Brown
Parker Brown
24,308 Points

Hey Matt F. got it to display finally, after opening up a new instance of Work Spaces. Copy/pasted code in and boom that it was. But I will make use of Codepen in the future. Will check out JSBin, thanks for the response and the recommendation.

Cheers