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 trial
Everton Carneiro
15,994 PointsHere is my solution to Student Record (Extra). Any thoughts?
Just want to share my solution so other students can compare. I think this is very helpfull.
function print(message) {
var outputDiv = document.getElementById("output");
outputDiv.innerHTML = message;
}
function showStudent(studentName) {
var nameIndex = [];
for (var i = 0; i < students.length; i++) {
if (studentName === students[i].name.toUpperCase()) {
nameIndex.push(i);
}
}
var message = "";
if (nameIndex.length === 0) {
message += "<h2>Student not found.</h2>"
} else {
for (var i = 0; i<nameIndex.length; i++) {
message += "<h2>Student: " + students[nameIndex[i]].name + "</h2>"
message += "<p>Tracks: " + students[nameIndex[i]].track + "</p>"
message += "<p>Points: " + students[nameIndex[i]].points + "</p>"
message += "<p>Achievements: " + students[nameIndex[i]].achievements + "</p>"
}
}
print(message)
}
while (true) {
var userInput = prompt("Type the name of the student to search or quit to finish.")
if (userInput === null || userInput.toUpperCase() === "QUIT") {
break
} else {
showStudent(userInput.toUpperCase())
}
}
1 Answer
KRIS NIKOLAISEN
54,974 PointsYour track and achievements are showing undefined. You should review your message.
Everton Carneiro
15,994 PointsEverton Carneiro
15,994 PointsOh yeah, I see. I have built this based on my own student object, not the one from the class. I should have posted my object here also. That's why you are getting undefined, because in my object the property is "tracks" instead of "track" and on "achievements" was just a typo from me. In my object I wrote "achievments" missing an "e". I just edit the original post, try it now.