Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.