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

Raul Cisneros
Raul Cisneros
7,319 Points

Lots of DRY code. I tried to avoid it but it would not work, so I used DRY code to make it work.

var student = [
  {name: "Susan", track: "Web Design", achievements: 2, points: 25},
  {name: "Melissa", track: "Full Stack Dev", achievements: 3, points: 50},
  {name: "Sarah", track: "Front End Dev", achievements: 4, points: 75},
  {name: "Jennifer", track: "IOS",achievements: 5, points: 100},
  {name: "Alexia", track: "Python", achievements: 6, points: 125}
];

function print(x) {
  document.getElementById('output').innerHTML = x;
}

while (true) {
  var userInput = prompt("Enter student name. Type 'quit' to exit");
  userInput = userInput.toLowerCase();
  if (userInput === "alexia") {
    alexia();
  } else if (userInput === "susan") {
    susan();
  } else if (userInput === "melissa") {
    melissa();
  } else if (userInput === "jennifer") {
    jennifer();
  } else if (userInput === "sarah") {
    sarah();
  } else if (userInput === "quit") {
    break;
  }
}

function susan() {
  for (var i = 0; i = 5; i++) {
  var message = '';
      message = message + '<h3>' + 'Student name: ' + student[0].name + '</h3>';
      message = message + '<p>' + 'Track: ' + student[0].track + '</p>';
      message = message + '<p>' + 'Acheivments: ' + student[0].achievements + '</p>';
      message = message + '<p>' + 'Points: ' + student[0].points + '</p>';
  print(message);
  break;
  }
}

function melissa() {
  for (var i = 0; i = 5; i++) {
  var message = '';
      message = message + '<h3>' + 'Student name: ' + student[1].name + '</h3>';
      message = message + '<p>' + 'Track: ' + student[1].track + '</p>';
      message = message + '<p>' + 'Acheivments: ' + student[1].achievements + '</p>';
      message = message + '<p>' + 'Points: ' + student[1].points + '</p>';
  print(message);
  break;
  }
}

function sarah() {
  for (var i = 0; i = 5; i++) {
  var message = '';
      message = message + '<h3>' + 'Student name: ' + student[2].name + '</h3>';
      message = message + '<p>' + 'Track: ' + student[2].track + '</p>';
      message = message + '<p>' + 'Acheivments: ' + student[2].achievements + '</p>';
      message = message + '<p>' + 'Points: ' + student[2].points + '</p>';
  print(message);
  break;
  }
}

function jennifer() {
  for (var i = 0; i = 5; i++) {
  var message = '';
      message = message + '<h3>' + 'Student name: ' + student[3].name + '</h3>';
      message = message + '<p>' + 'Track: ' + student[3].track + '</p>';
      message = message + '<p>' + 'Acheivments: ' + student[3].achievements + '</p>';
      message = message + '<p>' + 'Points: ' + student[3].points + '</p>';
  print(message);
  break;
  }
}

function alexia() {
  for (var i = 0; i = 5; i++) {
  var message = '';
      message = message + '<h3>' + 'Student name: ' + student[4].name + '</h3>';
      message = message + '<p>' + 'Track: ' + student[4].track + '</p>';
      message = message + '<p>' + 'Acheivments: ' + student[4].achievements + '</p>';
      message = message + '<p>' + 'Points: ' + student[4].points + '</p>';
  print(message);
  break;
  }
}
Steven Parker
Steven Parker
210,456 Points

It appears that this question was superseded by this later one. This one can probably be deleted.

Click the little rectangle with 3 dots in it to reveal the option.