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 trialJeffrey Davidson
26,147 PointsCheck For House Color Of Roof or Walls
I'm trying to figure out why my code isn't allowing me to move on to the next stage.
<?php
// add code below this comment
class Subdivision
{
public $houses = array();
public function filterHouseColor($color)
{
$lots = array();
if (($houses->roof_color == $color) || ($houses->wall_color == $color)) {
$lots[] = $houses;
}
return $lots;
}
}
?>
1 Answer
Simon Coates
28,694 PointsI found that it gives you an incorrect message. For me it was telling me that i wasn't testing on both roof and house color, but what was missing was $this. i always forget the $this, since in the languages i use, you don't have to use it.
<?php
class Subdivision
{
// add code below this comment
public $houses = array();
public function filterHouseColor($color)
{
$lots = array();
foreach($this->houses as $house)
{
if ($house->roof_color == $color){
$lots[] = $houses->lot;
}
else if ($house->wall_color == $color){
$lots[] = $houses->lot;
}
}
return $lots;
}
}
?>
Daniel Warner
3,981 PointsDaniel Warner
3,981 PointsThank you! I also forgot $this and was getting frustrated trying to figure out what was wrong.