Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Loops, Arrays and Objects Tracking Data Using Objects The Student Record Search Challenge Solution

This code doesn't seem to work

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Students</title> <link rel="stylesheet" href="styles.css"> </head> <body >

<div id = "output"></div> <script src = "student.js"></script> <script src = "studentscript.js"></script>

</body> </html>

var students = [ {

Name: "Dave", 
Track: "Front end Development", 
Achievements: 300, 
Points: 14000

}, {

Name: "Graham", 
Track: "IOS Development with swift",
Achievements: 175, 
Points: 10000

}, {

Name: "Steven", 
Track: "PHP Development", 
Achievements: 200, 
Points: 900

}, {

Name: "Rachel", 
Track: "Android", 
Achievements: 450,
Points: 20000

}, {

Name: "George", 
Track: "PHP", 
Achievements: 450,
Points: 20000

}

];

var message = ""; var student; var search;

function print(message){

 document.getElementById("output").innerHTML = message;

}

function getStudentReport(student){

    var report ="<h2>Student: " + student.Name + "</h2>";
    report +="<p>Track: " + student.Track + "</p>";
    report +="<p>Points: " + student.Points + "</p>";
    report +="<p>Achievement: " + student.Achievements + "</p>";
    return report;

}

while(true){
search = prompt("Search student records: Type the name [Jody] (or type quit to end)"); if(search === null || search.toLowerCase() === "quit"){ break; }

    for(var i = 0; i <students.length; i++){

        student = students[i];
        if(student.Name === search){
            message = getStudentReport(student);
            print(message); 
        }




    }

}

3 Answers

Steven Parker
Steven Parker
221,902 Points

Proper code quoting would help tremendously. See the Markdown Cheatsheet pop-up below the answer section. :arrow_heading_down:

But I was able to try your code anyway, and it works very well. Good job! :+1:

Now, why do you think it's not working? Did you try to enter names in lower case? Since you don't do any case conversion, it's important to enter the student name with proper capitalization. Or are you having a different problem?

Nick Ruiz
Nick Ruiz
18,492 Points

Are you not getting any output in the web browser? If so, I think your issue is with linking your scripts. It should look like this.

  <script src="js/students.js"></script>
  <script src="js/student_report.js"></script>

students.js and student_report.js are nested inside the js folder directory so without specifying that you probably won't get any output because it cannot find those files.

Nick Ruiz
Nick Ruiz
18,492 Points

also maybe the way you have your print function setup, not sure. Here's mine

function print(message){
 var outputDiv = document.getElementById("output");
  outputDiv.innerHTML = message;
}