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

Jose Perez Lopez
Jose Perez Lopez
8,936 Points

My solution to the multiple name, please let me know what you think and what I can improve

This is how I solve the last problem.

var html = ' ';
var student,userSearch;
var quit = false;
var counter = 0;
function print(message){
  var printDiv = document.getElementById('output');
  printDiv.innerHTML = message;
}
do{
  if(counter < 1){
    userSearch = prompt('Please enter the name of the student you wish to look for in the database or type "quit" to exit the program');
  }else if(counter > 0){
    userSearch = prompt('The Name you enter is not in the database. Please enter the name of the student you wish to look for in the database or type "quit" to exit the program');
  }
  if(userSearch === null || userSearch === 'QUIT'){
    quit = true;
  }
  userSearch = userSearch.toUpperCase();
  for(var i = 0; i < students.length; i++){
    student = students[i];
    if(userSearch === student.name.toUpperCase()){
      html += '<h2>' + 'Student: ' + student.name +'</h2>';
      html += '<p>Track: ' + student.track.join(', ') + '</p>';
      html += '<p>Achievements: ' + student.achievements + '</p>';
      html += '<p>Points: ' + student.points + '</p>';
      quit = true;
    }else if(userSearch !== student.name.toUpperCase()){
      counter++;
    }
  }
}while(!quit)
print(html);