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 trialFaisal Rahimi
4,019 PointsHelp with this challenge, The Student Record Search Challenge Solution. My code https://w.trhou.se/p4krz55qqm
Challenge is to find multiply students with the same name, Please do see my code and advice. I have been looking at what others have provided as solution, but none of them work.
Much Appreciated. https://w.trhou.se/p4krz55qqm
3 Answers
Thomas Nilsen
14,957 PointsNo offence, but I hate when people just say it doesn't work
What exactly doesn't work?
- Are you getting errors? (if yes - what kinds of errors?)
- Is the program running, but you're not getting the expected result?
Be a little more specific please :)
Faisal Rahimi
4,019 PointsYou sound little aggresive for a programmer haha,, program runs, but nothing appears, so in other words (it doesn't work).
Thomas Nilsen
14,957 PointsI modified your code slightly. I don't know exactly how you expect this to work, but try this:
var search;
var message = '';
var student;
var studentsFound = [];
var correctguess = false;
function print(message) {
var outputdiv = document.getElementById('output');
outputdiv.innerHTML = message;
}
function getstudentreport(students) {
var reports = [];
students.forEach(function (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>";
reports.push(report);
});
return reports.join('');
}
while (true) {
search = prompt("Hi welcome if you want to exit type (quit) or if you want students report type their name e.g (Jamila)");
if (search === null || search.toLowerCase() === "quit") {
break;
}
for (var i = 0; i < students.length; i++) {
student = students[i];
if (student.Name == search) {
correctguess = true;
studentsFound.push(student);
}
message = getstudentreport(studentsFound);
print(correctguess ? message : "Sorry we do not have student in the name of " + search);
}
}