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 trialAndrei Punei
14,051 PointsCannot access the proprieties in the objects!
///JavaScript Language
var students = [ {name: 'Marcel', track: 'Front-End development', achievements: 4, points: 2000, languages: ['Html', 'CSS3', 'JavaScript']}, {name: 'Iohanis', track: 'Back-End development', achievements: 8, points: 2750, languages: ['Html', 'JavaScript', 'PhP']}, {name: 'Popescu', track: 'PhP development', achievements: 5, points: 1400, languages: ['Html', 'JavaScript', 'PhP', 'SqL']}, {name: 'Simona', track: 'JavaScript development', achievements: 6, points: 1860, languages: ['Html', 'JavaScript', 'Node Js']}, {name: 'Marian', track: ' Web design', achievements: 7, points: 3000, languages: ['Html', 'CSS3']} ];
function print(message) { var outputDiv = document.getElementById('output'); outputDiv.innerHTML = message; }
var message = ''; var student;
for(var i = 0; i <= students.length; i++){ student = students[i]; message += '<h2>Student: ' + student.name + '</h2>'; } print(message);
///The console spits out an error saying that property 'name' is undefined
2 Answers
Tobias Helmrich
31,603 PointsHey Andrei,
firstly I'd like to recommend that you should post your code in a more legible way (e.g. indentation, line breaks) so it's easier for people who'd like to help you to understand your code.
I think the problem you're having exists because your for loop is missing its instructions. It looks like you forgot to finish your for loop.
After changing your code to this it should work:
var students = [
{
name: 'Marcel',
track: 'Front-End development',
achievements: 4,
points: 2000,
languages: ['Html', 'CSS3', 'JavaScript']
},
{
name: 'Iohanis',
track: 'Back-End development',
achievements: 8,
points: 2750,
languages: ['Html', 'JavaScript', 'PhP']
},
{
name: 'Popescu',
track: 'PhP development',
achievements: 5,
points: 1400,
languages: ['Html', 'JavaScript', 'PhP', 'SqL']
},
{
name: 'Simona',
track: 'JavaScript development',
achievements: 6,
points: 1860,
languages: ['Html', 'JavaScript', 'Node Js']},
{
name: 'Marian',
track: ' Web design',
achievements: 7,
points: 3000,
languages: ['Html', 'CSS3']
}
];
function print(message) {
var outputDiv = document.getElementById('output');
outputDiv.innerHTML = message;
}
var message = '';
var student;
for(var i = 0; i < students.length; i++) {
student = students[i];
message += '<h2>Student: ' + student.name + '</h2>';
}
print(message);
Andrei Punei
14,051 PointsCheers Toby! you're one cool guy
Tobias Helmrich
31,603 PointsHaha, thank you! I'm glad I could help!