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 Solution

Konrad Dziekonski
Konrad Dziekonski
7,798 Points

code review

Hello,

I must say I had hard times with this task and i still dont fully understand what is going on, perhaps you could explain the mechanics of this behavior. Bassicaly this is my code:

'strict mode'

let students = [
  {name: 'Kon Don',
  track: 'Front End Web Development, Full Stack JavaScript, Beginning Python, Web Design',
  achievements: 6598,
  points: 777 },
  {name: 'Dzon Dzwon',
  track: 'Java, iOS, Beginning Python, Web Design',
  achievements: 52745,
  points: 888 },
  {name: 'Bruce Lee',
  track: 'Beginning C#, PHP, Beginning Python, Web Design',
  achievements: 1240,
  points: 999 },
  {name: 'Mistrz Karate',
  track: 'Beginning Android, Learn HTML/;-0p;, Beginning Python, Web Design',
  achievements: 2554,
  points: 344 },
  {name: 'Pika Czu',
  track: 'UX Design, Intermediate Java, Beginning Python, Web Design',
  achievements: 4578,
  points: 177 }
];

let studentsHTML;

function print(x) {
    document.write(x);
}

for (let prop in students) {
      let  studentsHTML = '<ul>';
      studentsHTML += '<li>'+'<h2> Name: '  + students[prop].name + '</h2></li>';
      studentsHTML += '<li>'+'Track: ' + students[prop].track + '</li>';
      studentsHTML += '<li>'+'Achievements: ' + students[prop].achievements + '</li>';
      studentsHTML += '<li>'+'Points: ' + students[prop].points + '</li>';
      studentsHTML +='</ul>';
      document.write(studentsHTML)
    }

but when I want to use the print function and I do it outside the loop it showes 'undefined'. and this particular declaration is getting kind of greyish

  let  studentsHTML = '<ul>';

I cannot say I feel ok about my performance. I was trying to use the for loop but I did not store it in the variable as Dave did

student = students[i];

I think I was dointg something like this

 studentsHTML += '<li>'+'<h2> Name: '  + students[i].name + '</h2></li>';

but all i got was one set of data, i mean one object.

thanks

1 Answer

Ritesh Maharjan
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Ritesh Maharjan
Full Stack JavaScript Techdegree Graduate 21,195 Points

I don't really understand what you are trying to say but from what I can see, You are declaring studentsHTML twice. Once is outside the function and once is inside the function. Try removing the outside function and I also don't know what you are trying to do with function print(x)??

To do something like this studentsHTML += '<li>'+'<h2> Name: ' + students[i].name + '</h2></li>'; Are you using for loop that is for( let I =0; I < students.length; I++){

let studentsHTML = '<ul>'; studentsHTML += '<li>'+'<h2> Name: ' + students[i].name + '</h2></li>'; studentsHTML += '<li>'+'Track: ' + students[i].track + '</li>'; studentsHTML += '<li>'+'Achievements: ' + students[i].achievements + '</li>'; studentsHTML += '<li>'+'Points: ' + students[i].points + '</li>'; studentsHTML +='</ul>'; document.write(studentsHTML)

}