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

Rahim Spencer
Rahim Spencer
5,772 Points

Not sure what i'm doing wrong!


I've been trying to follow along with the challenge solutions, but can't seem to get anything to work even though i thought i had the same code as the instructor!

Can anyone take a look? Here's my code below.

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>Points: ' + student.points + '</p>';
  report += '<p>Achievements: ' + student.achievements + '</p>'; 
  return report;

while (true) {
  search = prompt('Search student records: type a name [Jody] (or   type "quit" to end)');
  if (search === null || search.toLowerCase() === 'quit') {

  for (var i = 0; i < students.length; i += 1) {
  student = students[i];
  if (student.name === search) {
    message = getStudentReport( student );

Thanks for your help! R

2 Answers

Damien Watson
Damien Watson
27,419 Points

Hi Rahim,

There are a few things. Firstly, there is nothing wrong with your code above. It does assume 2 things though, one is that you must have a container 'div' with id of 'output'. The second that you are checking in an array of 'students' for the name enterred.

<div id="output"></div>

Add this to the top of your Javascript:

var students = [];
students.push(new studentObject("John","Front End Development",3,820));
students.push(new studentObject("Theresa","Design",1,430));
students.push(new studentObject("Jules","PHP",4,140));
students.push(new studentObject("Kate","iOS",6,540));
students.push(new studentObject("Bob","Android",2,520));

function studentObject (name, track, achievements, points) {
    this.name = name;
    this.track = track;
    this.achievements = achievements;
    this.points = points;

Hi Rahim,

Can you post your HTML and students.js?

Thanks! Evan