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

Students list challenge. Not sure how to go further

Hello folks!

I am stuck (as always). I was excited I powered through the first steps, just to hit a wall. I'd like to have some help if possible, a feedback, but not a solution.

Could you please provide a little push, so that I can move in the right direction?

That's what I've built so far. I am not sure if all of this is necessary. However, I am able to log all the names in a new Array. What I want to do is to print the name that the user writes in the prompt dialog.

var userType = "";
var studentsList = ["jack", "alex",  "robert", "jill" , "angus"];
var quit = "quit";
var newStudentsList = [];

var students = [

  {name: "jack", track: "iOS", achievement: 5},
  {name: "alex", track: "Javascript", achievement: 7},
  {name: "robert", track: "Python", achievement: 0},
  {name: "jill", track: "Ruby", achievement: 15},
 {name: "angus", track: "C++", achievement: 3}
];


while (true) {

        var input = prompt("student name please"); 
        if ( input === "quit") {
  break;


        } if (studentsList.indexOf(input) > -1) { 
for (var i = 0; i < students.length; i++) {

  newStudentsList.push(students[i]);
}
  console.log(newStudentsList);

} 
}

The program asks questions in a loop. If the user writes a name that is in the system, then there's a match and all the students get logged in the console. Somehow I have to tell the system : write the information about the student you typed in.

In which direction should I move?

As always, I do appreciate your time!

Thanks, A.

2 Answers

Steven Parker
Steven Parker
229,732 Points

Here's a few hints (no code):

The prompt should be done before the search loop. This allows the program to check each name for a match without asking for more input. If you want to be able to do more than one search, you'll need another loop around everything.

You'll also need a process to convert the contents of a student object into a string to make it visible on the page. In the next video this is done in a function.

Hello Steven,

I was wondering where you've been! I always see you around, and I was just reading about some answers you left to other students.

I am sometimes surprised on how simple is the solution. I find myself thinking about crazy calculations when it could be done in two lines of code.

Thanks for your answer, I appreciate your support!

I am posting here my solution for anyone interested in knowing more about the challenge. This is not as dry as some responses here, because I am asking the system to store the answer to a new Array, which is not needed. I am also not using a nice styled message at the bottom, or .toLowerCase() as an option, however the core of the program is there

var userType = "";
var quit = "quit";
var message = '';
var students = [

  {name: "jack", track: "iOS", achievement: 5},
  {name: "alex", track: "Javascript", achievement: 7},
  {name: "robert", track: "Python", achievement: 0},
  {name: "jill", track: "Ruby", achievement: 15},
 {name: "angus", track: "C++", achievement: 3}
];


while (true) {

        var input = prompt("student name please"); 
        if ( input === "quit") {
  break;

      } for (var i = 0; i < students.length; i++) { 

 if ( input === students[i].name) { 

   var newArray = [];
   newArray.push(students[i].name + " " + students[i].track + " "+  students[i].achievement)
  alert(newArray);
}
}
}