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

Erik L
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Erik L
Full Stack JavaScript Techdegree Graduate 19,470 Points

my code is not working

var students = [
  {
    name: 'erik',
    track: 'Full Stack Javascript',
    achievements: '100',
    points: '3000'
  },
  {
    name: 'jackie',
    track: 'Python',
    achievements: '50',
    points: '300'
  },
  {
    name: 'jackie',
    track: 'CSS',
    achievements: '400',
    points: '2000'
  },
  {
    name: 'alicia',
    track: 'PHP',
    achievements: '5000',
    points: '3000'
  },
  {
    name: 'betty',
    track: 'Java',
    achievements: '5000',
    points: '4000'
  }
];
var message = '';
var student;
var search;

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

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

print(message);

while (true) {
  search = prompt("Search for a student's name. Type 'list' to show all of the student records available and 'quit' to exit");
  if (search === null || search.toLowerCase() === 'quit') {
    break;
  }
  for (var i = 0; i < students.length; i++) {
    student = students[i];
    if (student.name === search ) {
      message = getStudentReport( student );
      print(message);
    } else {
      print( search + ' that name is not on our records.');
    }

  }
}

1 Answer

what is the issue that your facing? can you be a bit more specific