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

Mariana Castilho
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Mariana Castilho
Front End Web Development Techdegree Graduate 13,842 Points

Different logic but I guess it shoud work

Hi! I did the challenge using a slightly different structure but I guess it should work...but after I enter the student name in the prompt, nothing is displayed in the page.

while(true) {

  var input = prompt('Selecione nome para pesquisar');

  if(input.toLowerCase() === 'quit' || input === null) {
    break;
  } else {

    for (var i = 0; i < student.length; i += 1) {
      studentName = student[i].name;
      if(studentName === input) {

    message += '<h2>Student: ' + student.name + '</h2>';
    message += '<p>Track: ' + student.track + '</p>';
    message += '<p>Points: ' + student.points + '</p>';
    message += '<p>Achievements: ' + student.achievements + '</p>';

        print(message);
  }
  }

  }
}

1 Answer

Dmitry Polyakov
Dmitry Polyakov
4,989 Points

When you loop through students array in your for loop you need to grab the student object, not just student's name

studentName = student[i].name; - this line might cause the issue

We have student variable initialised at the top and we need to assign student object to this variable

student = students[i];