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

Marcel Carey
Marcel Carey
2,890 Points

I can't search for the student records.

let html = ''
let student
let search
let students = [
{
     name: 'Josh',
     track: ['Html', 'CSS', 'JavaScript'],
     achievments: 'Front End Development',
     points: 220



},
{
    name: 'Lacie',
    track:[ 'Html', 'CSS', 'JavaScript'],
    achievments: 'Front End Development',
    points: 587
},
{
    name: 'Elle',
    track: ['Html', 'CSS', 'JavaScript'],
    achievments: 'Front End Development',
    points: 550
},
{
    name: 'Mark',
    track: ['Html', 'CSS', 'JavaScript'],
    achievments: 'Front End Development',
    points: 220
},
{
    name: 'Brian',
    track: ['Html', 'CSS', 'JavaScript'],
    achievments: 'Front End Development',
    points: 580
}
]



function getStudentReport( student ) {
    let report = `<h2> Student: ${student.name}</h2>`
    report += `<p> Track: ${student.track.join(', ')}</p>`
    report += `<p> Achievments: ${student.achievments}</p>`
    report += `<p> Points: ${student.points}</p>` 
    return report

}

while (true) {
    search = prompt('Search for a student records [Mark] you can also quit to exit')
if (search === null || search.toLowerCase() === 'quit') {
    break
}
for (let i = 0; i < students.length; i ++){
    student = students[i]
    if (student.name === search) {
        messages = getStudentReport( student )
        print(messages)

    }

}
}




function print(messages) {
  let divOutput = document.getElementById('output')
  divOutput.innerHTML = messages
}


print(html)

2 Answers

Steven Parker
Steven Parker
210,475 Points

The variable "html" is not used in the program and remains an empty string.

So the "print(html)" at the end of the program wipes out any message that the rest of the program would have displayed.

Marcel Carey
Marcel Carey
2,890 Points

So I did that as well and still nothing changes

Steven Parker
Steven Parker
210,475 Points

I'm not sure what you mean by "did that". If I just remove the last line the program works as expected.

Be aware that you won't see anything until after you type "quit" (see the Teacher's Notes for details).

Marcel Carey
Marcel Carey
2,890 Points

Ok so It works, I had to create another javascript file. I was wondering if i could do it all on one file instead of multiples?

Steven Parker
Steven Parker
210,475 Points

Sure, when I was testing I had only one file.