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 trialkevin hudson
Courses Plus Student 11,987 PointsJavascript build an array of objects part two code project
Please review my code for the array of Objects part 2 project.
//Objects challenge. Display a list of students in HTML from array of objects.
//global variables
var html = '';
// Array with student objects
var students = [{
name: 'John Macintire ',
track: 'Web Design',
achievements: '74',
points: '321'
},
{
name: 'Jeff Macintire ',
track: 'Web Design',
achievements: '71',
points: '308'
},
{
name: 'Bear Grills ',
track: 'Front End Development',
achievements: '122',
points: '481'
},
{
name: 'Dirk Diggler',
track: 'Back End Development',
achievements: '10',
points: '2'
},
{
name: 'Rainbow Sue ',
track: 'Web Design',
achievements: '23',
points: '97'
},
];
/*Functions*/
//Capitalize First letter of string value
function capFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
//Build HTML ordered list of students information. Used if for changing object key style
function loopArrayObject(arr) {
for (var i = 0; i < arr.length; i++) {
var tempObj = arr[i];
html += '<ul style="list-style:none">';
for (var key in tempObj) {
if (key === 'name') {
html += '<h2 style=" color: #79797C; font-weight: bold"> Student : ' + tempObj[key] + '</h2>';
} else {
html += '<li>' + capFirstLetter(key) + ' : ' + tempObj[key] + '</li>';
}
}
html += '</ul>';
}
return html;
}
// simple print function targeting html tag id
function print(message) {
document.getElementById('output').innerHTML = message;
}
//Call functions here
print(loopArrayObject(students));
//