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

Claudia Luk
Claudia Luk
9,337 Points

My solution for the extra challenges

function print(message) {
    var elementItem = document.getElementById('container');
    elementItem.innerHTML = message;
}

/*
* This function will print the objects found
* or a message for the ones not found
*/
function searchName(name) {
    var message = '';
    for (var i = 0; i < students.length; i++) {
        student = students[i];
        if (name === student.name) {
            message += '<h2>Student: '+ student.name +'</h2>';
            message += '<p>Track: '+ student.track +'</p>';
            message += '<p>Achievements: '+ student.achievements +'</p>';
            message += '<p>Points: '+ student.points +'</p>';
            print(message);
        }
    }
    if (message === '') {
        message = "No student name " + name + " was found";
        print(message);
    }
}

/*
* Main part of the script
* everything starts here
*/
while (1) {
    var input = prompt(
        "Search student records: type a name[Jody](or type 'quit' to end)"
    );
    if (input === null || input === '' || input.toLowerCase() === 'quit') {
        break;
    } else {
        searchName(input);
    }
}

1 Answer

Aaron Coursolle
Aaron Coursolle
18,014 Points

Does your program need to be debugged?

I already notice that this line doesn't match the default html provided with the lesson:

Your Javascript file is looking for an id named "container":

 var elementItem = document.getElementById('container');

But the only id in the provided html is:

<div id="output">