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

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
231,275 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
231,275 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
231,275 Points

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