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

Hi all, is this a good solution for the final challenge?

// variables
var studentslist = [
  {
    naam: 'loek',
    functie: 'illustrator',
    leeftijd: 40
  },
  {
    naam: 'loek',
    functie: 'vormgever',
    leeftijd: 10
  },
  {
    naam: 'theo',
    functie: 'boekhouder',
    leeftijd: 34
  },
  {
    naam: 'chris',
    functie: 'schrijver',
    leeftijd: 43
  }
]

// selected array
var foundStudent = [];
var antwoord;
var student;

//print function
function print(message) {
  var div = document.getElementById('output');
  div.innerHTML += message;
}

// ask for a name
zoek = window.prompt('search a student');

  // for looping trough studenten, pass it on to foundStudent
  for (var i=0; i<studentslist.length; i+=1) {

    if (zoek === (studentslist[i].naam)) {
      foundStudent.push(studentslist[i]);
        }
      }

  // printing out the foundStudent list
  for (var i=0; i<foundStudent.length; i+=1) {
    var uitdraai = '<li>' + foundStudent[i].naam + '</li>';
    uitdraai += '<li>' + foundStudent[i].functie + '</li>';
    uitdraai += '<li>' + foundStudent[i].leeftijd + '</li><br>';
    print(uitdraai);
  }

  print("Thank you, goodbye");