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

My extra credit solution.

https://w.trhou.se/weg3j34nu8

Happy to get constructive feedback. Seems to do the trick, although it would be nice if the names stored were capitalized. Also, the extra white space from message being declared as a blank space.

Hope it helps someone!

Raphael Chen
seal-mask
.a{fill-rule:evenodd;}techdegree
Raphael Chen
Front End Web Development Techdegree Student 8,751 Points

Hi Adam,

Sorry, I don't quite understand the purpose of setting up the variable EndProgram = false.

Was the purpose of this to just know when to state the program will end? which is why you put in (EndProgram === false) in the do-while loop to indicate it being true. Not sure if I have explained what I wanted to clarify properly but do hope you got the idea of what I am asking.

2 Answers

I went with...

var message = "";
var userSearch;
var student;

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 ) {
  userSearch = prompt("Type a student name to pull their record. Type quit to exit.");
  if ( userSearch === null || userSearch.toLowerCase() === 'quit' ) {
    break;
  } 

  for (var i = 0; i < students.length; i += 1 ) {
  student = students[i];
  if ( student.name === userSearch ) {
    message += getStudentReport(student);
    message += "<br>";
  } 
  }

  if (message === "") {
    message += "<p>No user named " + userSearch + " was found.</p>";
    print(message);
  } else {
    print(message)
  }

}

Seems to work well, although the check to see if the message is empty seems a little hack-y. Anyone got a better idea for that?

(message == 0) seems to work for me, Ed.

But this is my first comment, so at this point I'm assuming I'm missing something. Haha.

Armin Kadic
Armin Kadic
16,242 Points

This guy is a life saver! Thank you!