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 trialB P
4,563 Points"Oops! It looks like Task 1 is no longer passing"
I already asked for help on this once, and got one answer, but it didn't help..
This code keeps returning error Oops! It looks like Task 1 is no longer passing", Task 1 was just making a class Subdivision and public property $houses in it. What the hell is going on???
<?php
// add code below this comment
class Subdivision {
public $houses = [];
public function filterHouseColor($color) {
foreach($this->houses as $house) {
if($house->roof_color == $color || $house->wall_color == $color) {
$matchingHouses[] = $house;
}
}
return $matchingHouses;
}
}
?>
4 Answers
Serhii Lihus
6,352 PointsHi there!
You need to declare $matchingHouses inside of the filterHouseColor method. And put return statement inside of the method body.
class Subdivision {
public $houses = [];
public function filterHouseColor($color) {
$matchingHouses = [];
foreach($this->houses as $house) {
if($house->roof_color == $color || $house->wall_color == $color) {
matchingHouses[] = $house;
}
}
return $matchingHouses;
}
}
Hope this will help.
Best regards!
Serhii Lihus
6,352 Pointsforgot about dollar sign in expression ;)
$matchingHouses[] = $house;
B P
4,563 PointsYea, was just about to post about that. Works now.
Serhii Lihus
6,352 PointsYou welcome )
B P
4,563 PointsB P
4,563 PointsThat still does not work though. Even tried completely copying your method, and that gives error "Bummer! Cannot use temporary expression in write context in index.php on line 10"