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 trialDigvijay Jaiswal
5,565 PointsThe Student Record Search Challenge Solution Part2
Initially used the For loop inside the For loop as mentioned in the program below to print all the Property and the Value but I am wondering if that same For loop structure can be used to solve the second part of the challenge?
var students = [
{ Name: 'DJ',
Track: 'Full Stack JavaScript',
Achievements: 2,
Point: 5
},
{ Name: 'Nick',
Track: 'HTML',
Achievements: 2,
Point: 10
},
{ Name: 'Pasan',
Track: 'iOS',
Achievements: 3,
Point: 15
},
{ Name: 'Dave',
Track: 'JavaScript',
Achievements: 6,
Point: 20
},
{ Name: 'Guil',
Track: 'CSS Layout',
Achievements: 4,
Point: 15
}
];
for (i=0; i<students.length; i++)/*Loop to access every single element from the array*/{
document.write('<br>');
for(var prop in students[i])/*Loop is to access every property from the objects*/{
document.write(prop, ':', students[i][prop], '<br>')
}
}
2 Answers
Steven Parker
231,275 PointsA similar loop would naturally be part of the search process.
But there will be additional code involved to test each record for a match with the search conditions and show only the records that match.
The video you created this question from (and is linked to the "watch video" button up top ) shows this process in detail.
Digvijay Jaiswal
5,565 PointsSteven Parker THanks, ill check it out! :)