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

Vadim Selivonchik
Vadim Selivonchik
3,997 Points

comment my solution please

let html = '';
let student;
let request;
let studentNames = [];
let names = [];

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

for (let i = 0; i < students.length; i++) {
  student = students[i];
  studentNames.push(student.name);
}

function getReport (student) {
  report = '<h4>Student: ' + student.name + '</h4>';
  report += '<p>Track: ' + student.track + '</p>';
  report += '<p>achievements: ' + student.achievements + '</p>';
  report += '<p>points: ' + student.points + '</p>';
  return report;
}

for (let i = 0; i < students.length; i++) {
  student = students[i];
  names.push(student.name);
} 

while (true) {
  request = prompt("Type name or quit");
  if (request == null || 
    request.toLowerCase() == 'quit') {
    break;
  } else if ( names.indexOf(request) == -1 ) {
    alert('there is no that student');
  }
  for (let i = 0; i < students.length; i++) {
    student = students[i];
    if (request == student.name) {
      html += getReport(student) ;
      print(html);
    } 

  }
}

2 Answers

Steven Parker
Steven Parker
231,236 Points

At first glance, it looks like you have the classic code implementation for this exercise.

Good job. :+1:

Steven Parker
Steven Parker
231,236 Points

Anything I can think of you might improve would involve a technique that probably hasn't been covered yet (like template literals).