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 trialJames Tan
3,188 PointsWhat is wrong with my code?
I can't seem to find anything wrong with it whatsoever but the object refuses to print even with the correct input in the prompt. somebody help me please thank you.
var students = [
{
Name : 'sarah',
Track : 'ios',
Achievements : 5,
Points : 1256
},
{
Name : 'john',
Track : 'java',
Achievements : 6,
Points : 1354
},
{
Name : 'robert',
Track : 'javascript',
Achievements : 7,
Points : 1458
},
{
Name : 'jefferey',
Track : 'python',
Achievements : 8,
Points : 1924
},
{
Name : 'mason',
Track : 'ruby',
Achievements : 9,
Points : 1276
}
]
var student;
var search;
var message;
function print (message){
var outputDiv = document.getElementById('output');
outputDiv.innerHTML = message;
}
function getStudentReport( student ){
var report = '<h2>Student: ' + student.name + '</h2>';
report += '<p>Track : ' + student.Track + '</p>';
report += '<p>Achievements : ' + student.Achievements + '</p>';
report += '<p>Points : ' + student.Points + '</p>';
return report;
}
while (true) {
search = prompt('search student records : type a name ( or type "quit" to end)');
if (search === null || search.toLowerCase() === 'quit') {
break;
}
for ( var i = 0 ; i < students.length ; i+=1 ){
student = students[i];
if(student.name === search){
message = getStudentReport( student );
print(message);
}
}
}
2 Answers
Steven Parker
231,248 PointsJavaScript is case-sensitive, so identifiers only match if they are exactly the same, including case.
The code shown has mutliple references to the "name" property of a student record. But none of the records in the students array have this property. They do, however, have a "Name" (capital "N") property.
James Tan
3,188 Pointsoh got it thank you!