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

Andrey Konovalenko
Andrey Konovalenko
9,409 Points

My solution for the Student Search Record Challenge

Hi everybody !!!

Here is my solution: http://codepen.io/Bereon/pen/QNPwLa

My search script can:

print students with equal names, alerting when you input name which dose not exist in database. Will be grateful for your comments,

Andrey

2 Answers

Shane Oliver
Shane Oliver
19,977 Points

The while loop in the searchname function always evaluates to true and keeps showing the prompt. You should also change the user input and the name data from the name object into a single case so varying input of the name can still be evaluated.

Andrey Konovalenko
Andrey Konovalenko
9,409 Points

Hi Shane Oliver! Thank you for comment. I changed letters of input name and nameList object to lowercase, as you recommended. But I'm not sure about while loop issue. The aim of creating the infinite loop was to keep asking questions until user type "quit" or click "cancel".

New version of my solution: http://codepen.io/Bereon/pen/zqXBxp

var students = [

  {name: 'Peter', track: ['perl', 'python'], achievements: 0, points: 10},
  {name: 'David', track: ['pinky', 'duster'], achievements: 10, points: 80},
  {name: 'Justin', track: ['curl', 'php'], achievements: 5, points: 60},
  {name: 'John', track: ['ruby', 'javascript'], achievements: 8, points: 1000},
  {name: 'Twister', track: ['html', 'css'], achievements: 24, points: 70}

];

var printer = function (){
    for(var i = 0; i < students.length; i++){
       for(var key in students[i]){
         if(key === 'name'){
            document.write("<p>" + students[i][key] + "</p>");
         }else{
            document.write("<p style=\"padding-left: 20px;\">"+ key + ": " + students[i][key] + "</p>");
         }
       }
    }
}

printer();