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

My solution to the whole challenge

This is my solution to the challenge. Could split it in to more functions if any of it was required again:

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

while (true) {
    var studentRec= '';
    var response = prompt("please enter the name of the student you are searching for");
    response = response.toLowerCase();
    if (response == 'quit') {
        break;
    } else {
        for (var i = 0; i < students.length; i += 1) {
            if (response == students[i].name.toLowerCase()) {
                for (var key in students[i]) {
                    if (key == 'name') {
                        studentRec += '<h1>' + key + ' : ' + students[i][key] + '</h1>';
                    }
                    {
                        studentRec += '<p>' + key + ' : ' + students[i][key] + '</p>';
                    }

                }
            }
        }
        if (studentRec.length == 0) {
            alert('No student found with the name ' + response + '. Please try again');
        }
    }
    print(studentRec);
}

I think I had more issues reformatting this post than I did with the challenge. Note to self: there needs to be a new line between any text and your (```)