Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
210,475 Points

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

Good job. :+1:

Steven Parker
Steven Parker
210,475 Points

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