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

Object Challenge : It won't show any message when I use 「 .innerHTML 」

var students = [ { name : "Tani", Track : "Visual Design", Achievements : 10, Point : 10.5 }, { name : "Lisa", Track : "Web Design" , Achievements : 10, Point : 11.5 } ];

var message = ""; var student; for (i = 0 ; i > students.length ; i += 1) { student = students[i]; message += "<h2> Student :" + student.name + "</h2>"; message += "<p> Track :" + student.Track + "</p>"; message += "<p> Achievements :" + student.Achievements + "</p>"; message += "<p> Point :" + student.Point + "</p>"; }

document.getElementById ("text").innerHTML = message;

1 Answer

I went ahead and formatted your code using the Markdown Cheatsheet to make it more readable:

var students = [
  {
    name : "Tani",
    Track : "Visual Design",
    Achievements : 10,
    Point : 10.5
  },
  {
    name : "Lisa",
    Track : "Web Design" ,
    Achievements : 10,
    Point : 11.5
  }
];

var message = "";
var student;

for (i = 0 ; i > students.length ; i += 1) {
  student = students[i];
  message += "<h2> Student :" + student.name + "</h2>";
  message += "<p> Track :" + student.Track + "</p>";
  message += "<p> Achievements :" + student.Achievements + "</p>";
  message += "<p> Point :" + student.Point + "</p>";
}

document.getElementById ("text").innerHTML = message;

I don't know which video/challenge you're on, or the larger code this is a part of, but I do see one thing that would definitely break your code. In your if statement, you're setting your loop to run while i is greater than (>) students.length, rather than less than (<). Since i is set to start at 0, but only run while it's greater than the length of the students array, the condition will never be met and the code will never run.

If your code still doesn't work after that, can you include a snapshot of your workspace? Let me know!

It's work thank you, it should be less than (<), my wrong typing.

Glad it worked!