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 trialSteven Andrews
14,299 PointsHelp with wall_color and roof_color code challenge
The challenge say to compare the parameter pass ($color) to the roof and wall color and record the house's lot number to an array and return it.
As I thought this was pretty straight forward, my code is below:
<?php
// add code below this comment class Subdivision{ public $houses = array();
public function filterHouseColor($color){
$lot = array();
if($house->roof_color == $color || $house->wall_color == $color){
$lot[] = $house->lot;
}
return $lot;
}
}
?>
Thanks in advance for the help!
<?php
// add code below this comment
class Subdivision{
public $houses = array();
public function filterHouseColor($color){
$lot = array();
if($this->house['roof_color'] == $color || $this->house['wall_color'] == $color){
$lot[] = $house->lot;
}
return $lot;
}
}
?>
1 Answer
Simon Coates
28,694 PointsA lot of people have been having trouble with that challenge in the last couple days. Try something like
public function filterHouseColor($color)
{
$arr = [];
foreach($this->houses as $ahouse)
{
if($ahouse->roof_color === $color || $ahouse->wall_color === $color) {
$arr[] = $ahouse->lot;
}
}
return $arr;
}
Steven Andrews
14,299 PointsThanks Simon!
Steven Andrews
14,299 PointsSteven Andrews
14,299 PointsMy original code is below:
<?php
// add code below this comment class Subdivision{ public $houses = array();
public function filterHouseColor($color){ $lot = array(); if($house->roof_color == $color || $house->wall_color == $color){ $lot[] = $house->lot; }
return $lot; } }
?>