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

Check the solution! Right way. ( don't sure)

var student;
var html = '';

// if there are two or more names in the list it prints all of them
var getInfo = function (student) {
    html += '<h2>Name: ' + student.name + '</h2>';
    html += '<p>Track: ' + student.track + '</p>';
    html += '<p>Achievements: ' + student.achievements + '</p>';
    html += '<p>Points: ' + student.points + '</p>';
    return html;
}

while (true) {
var require = prompt("Whom are you finding?");
// clear before new search to print only fresh search
html = '';
    if ( require === 'quit' || require === null ){
        break;
    } else {
        // check the condition for each object
            for ( var i = 0; i < students.length; i++ ) {
            student = students[i];
            if ( require.toLowerCase() === student.name.toLowerCase() ) {
                print( getInfo( student ) );
            }
        }
        // if loop end type the message, and loop start again
        if ( html === '' ) {
                alert( ' There\'s no that student!');
        }
    }
}

1 Answer

Nikolas Soley
Nikolas Soley
10,412 Points

I think thatΒ΄s you can use a complete name, with the last name in the string.