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 trialDamian Toczek
4,471 PointsHow to return an collection array of house objects that match the passed color parameter.
This is bit confusing because i don't know why it's not working. I'm getting each house and then compare the walls/roofs with the passed color. If it's true it adds the house to the output array.
<?php
// add code below this comment
class Subdivision
{
public $output = array();
public $houses = array();
public function filterHouseColor($color)
{
foreach ($this->houses as $house){
if($this->roof_color === $color || $this->wall_color === $color){
$this->output[] = $house;
}
}
return $this->output;
}
}
?>
This part here was wrong:
if($this->roof_color === $color || $this->wall_color === $color){
1 Answer
Jennifer Nordell
Treehouse TeacherHi there, Damian Toczek ! You're doing terrific and you're super close! Take a look at this line:
foreach ($this->houses as $house)
This is set up just fine. But it also means that for every iteration through that collection, the individual item is assigned to the variable $house
. Then in the very next line, you set up your if
statement just brilliantly, but you're comparing the roof_color
and wall_color
of this
. You should be comparing the roof_color
and wall_color
of the $house
.
Making that change will cause this to pass. Hope this helps!
Damian Toczek
4,471 PointsDamian Toczek
4,471 PointsHi, thank you, I've already noticed that.