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 Multiple Items with Arrays Build a Quiz Challenge, Part 2 Solution

What would I do if I want to search an array for certain variables + display those

Hi all, what would be the code for the following example:

Display all students who took the HTML course. OR: Display all students who took the HTML course AND have results >80%.

Any ideas? Cheers, Nicole

1 Answer

Steven Parker
Steven Parker
231,269 Points

The button above links to the video on creating a question/answer quiz program. But assuming that you're talking about an array of objects representing students with various properties, here would be some generic approaches to your objectives:

// Display all students who took the HTML course
for (let i=0; i < students.length; i++) {
  if (students[i].courses.includes('HTML')) displayStudent(students[i]);
}

// Display all students who took the HTML course AND have results >80%
for (let i=0; i < students.length; i++) {
  if (students[i].courses.includes('HTML') && students[i].results > 80)
    displayStudent(students[i]);
}