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
195,812 Points

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

Good job. :+1:

Steven Parker
Steven Parker
195,812 Points

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