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

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

Philip Schultz
seal-mask
.a{fill-rule:evenodd;}techdegree
Philip Schultz
Full Stack JavaScript Techdegree Student 5,242 Points

Can't find my mistake. My browser isn't acting like the instructors.

Can someone help me understand why my code isn't working like Dave McFarlands in the video. I'm sure I made a mistake, but can't seem to find it. When I run this in my browser, it doesn't refresh like his does. For example, when I search for 'Jody' nothing happens in the background of the prompt box, like it does for Dave. However, if I search for the student the enter 'quit' on the next prompt, the information does appear. Please let me know if I missed a step, thanks.

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


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

function report(student){

     var report ="<h1> Name: " + student.name + "</h1>";
     report += "<p> Track: " + student.track + "</p>";
     report += "<p> Achievements: " + student.achievements + "</p>";
     report += "<p> Points: " + student.points + "</p>";
     return report;
}

while(true){
    search = prompt("What is the first name of the student that you are looking for? Or type 'quit' if you want to end the program. ");

    if(search === null || search.toLowerCase() === 'quit' ){
        break;
    } 
    for(var i = 0; i < students.length; i++ ){
        student = students[i];

        if(student.name === search){
            message = report(student);
            print(message);
        }
    }
}

1 Answer

Read the teacher's notes for the video

Philip Schultz
seal-mask
.a{fill-rule:evenodd;}techdegree
Philip Schultz
Full Stack JavaScript Techdegree Student 5,242 Points

Opps didn't catch that, thank you. Actually it says that it should be printing out every successful search that I made, but it only prints out the most recent successful search.... any ideas why that is? Thanks again