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 trialAlfredo Prince
6,175 PointsA little guidance here please.
My proposed code is below and this is the question. Return an array containing the public lot parameter of each house object whose public roof_color OR wall_color match the passed color parameter.
Here's what I get when I run the code below
Your return value should be an array.
Please help me to figure out what's going wrong.
<?php
// add code below this comment
class Subdivision
{
public $houses = array();
public function filterHouseColor($color)
{
foreach($houses as $house){
if($roof_color || $wall_color == $this->$color){
$this->$house[] = $house;
}
return $houses['house'];
}
}
}
?>
1 Answer
Eric Drake
6,339 PointsAlfredo,
This looks like a duplicate conversation. For the sake of keeping the answer in each conversation, I'll post what we had discussed here as well.
This is a confusing challenge. Here are a few details that the challenge doesn't give you that you need to know:
- The houses property is an array of House objects.
- The House class has three public member variables: lot, roof_color, and wall_color. You are supposed to loop through the houses array and create a separate array that only contains the House objects that have a roof_color or wall_color equal to the color passed to the filterHouseColor method. The result looks something like this:
public function filterHouseColor($color) { $matches = array(); for($i=0;$i<count($this->houses);$i++){ if ($this->houses[$i]->roof_color == $color || $this->houses[$i]->wall_color == $color) { $matches[] = array('lot' => $this->houses[$i]->lot); } } return $matches; }