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

Scout O'Keefe
Scout O'Keefe
7,812 Points

My code was a little different than that in the video, but already solved the multiple people with the same name problem

function print(message) {
  var outputDiv = document.getElementById('output');
  outputDiv.innerHTML = message;
}

var students = [
  {
    name: 'Scout',
    track: 'Front End Web Development',
    achievements: 28,
    points: 2508
  },
  {
    name: 'Luis',
    track: 'Web Design',
    achievements: 30,
    points: 3025
  },
  {
    name: 'Clara',
    track: 'Rails Development',
    achievements: 58,
    points: 14930
  },
  {
    name: 'Kathryn',
    track: 'iOS Development',
    achievements: 28,
    points: 2596
  },
  {
    name: 'Scout',
    track: 'Learn Python',
    achievements: 47,
    points: 5964
  }
]

while (true) {
  var searchQuery = prompt('Please enter the name of the student you or looking for or type "quit" to exit');
  var message = '';
  if (searchQuery === null || searchQuery.toLowerCase() === 'quit') {
    break;
  } else {
    for (var i = 0; i < students.length; i += 1) {
      var currentStudent = students[i]
      if (searchQuery.toLowerCase() === currentStudent.name.toLowerCase()){
          message += '<h2>Name: ' + currentStudent.name + '</h2><ul>';
          message += '<li>Track: ' + currentStudent.track + '</li>';
          message += '<li>Achievements: ' + currentStudent.achievements + '</li>';
          message += '<li>Points: ' + currentStudent.points + '</li></ul>';
      } 
    }
  }
  if (message === '') {
    message += 'Sorry, there are not student records for ' + searchQuery;
  }
  print(message);
}