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

Siddharth Pande
Siddharth Pande
9,046 Points

Feedback on my code

var div = document.getElementById('output');

var students = [
  {
    name: "Siddharth",
    track: "Front-End Developer Course",
    achievements: "got badges",
    points: 4938,
  },

  {
    name: "Dave",
    track: "Golang",
    achievements: "Teacher at Treehouse",
    points: 14567,
  },

  {
    name: "Brendan",
    track: "Python for Beginners",
    achievements: "Moderator at Treehouse",
    points: 83000,
  },

  {
    name: "Anil",
    track: "HTML Basics",
    achievements: "Newbie",
    points: 25,
  },

  {
    name: "Saurabh",
    track: "Front-End Design",
    achievements: "Newbie",
    points: 56,
  },

];




function arrangeRecord(arr) {
  for (i = 0; i <= students.length; i += 1) {
    div.innerHTML += "<h4>Student: " + students[i].name + "</h4>" +
                     "<p>Track: " + students[i].track + "</p>" +
                     "<p>Points: " + students[i].points + "</p>" +
                     "<p>Achievements: " + students[i].achievements + "</p>                          </br>"; 
    }
}


  arrangeRecord(students);

1 Answer

Hello

This is a good starting point for using data. We hold data in JSON quite a lot with JavaScript so doing the above is a good starting point.

There is a few things i would suggest if you wanted to make this a little more advanced as if it was a real scenario.

  • Your arrangeRecord function could be simplified to one line. Change your code to be for ... in / for ... of.
  • Put the students in a JSON file, see if you can figure out how to import it and readFile

Bonus

  • Add an Edit button and try work out how to writeFile

The above will be really good practice at handling JSON data which is used all the time, see if you can figure them out, Give me a message if you get stuck, ill give a bit more info.

Good Luck

Siddharth Pande
Siddharth Pande
9,046 Points

Thanks for your answer and I will work on the points that you mentioned here. If stuck I will contact you.