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 trialChris Hummel
13,960 PointsThese instructions are kind of confusing. Can someone help clarify the ask here?
detailsRoom should accept a single object parameter named $room. The $room object will have the follow methods:
getName: will return a string
getDimensions: will return and array of size integers
Add a return value to the detailsRoom method that displays "name Dimensions: length x width", where name is returned from the room getName method and length x width is returned from the render displayDimensions method.
You will need to call the static method displayDimensions from within the Render class and pass the dimensions from the $room object using the getDimensions method
Final Output Example: Kitchen Dimensions: 12 x 14
Am I supposed to be making the getName and getDimensions methods? Do I need to be making a room class? It's worded kind of funky, and I'm having a really hard time deciphering the ask here.
<?php
class Render {
public function getDimensions()
{
return $self->displayDimensions;
}
public function getName()
{
}
public static function displayDimensions($size)
{
$output = implode(" x ", $size);
return $output;
}
}
?>
2 Answers
Jennifer Nordell
Treehouse TeacherHi there, Chris Hummel ! This part of the challenge is trying to tell you that somewhere there is another class file that you can't see that makes a Room
. The $room
is an instance of that class and will be sent in as a parameter. It's only asking you to make the detailsRoom
method.
The Room
class which exists elsewhere has a method called getName()
and getDimensions
. You will use the getName()
which returns a string like "Kitchen" and the getDimensions()
which returns an array like [14, 12]
where the numbers are the length and the width. You're going to need that so that you can send in that array to the displayDimensions
method as the $size
.
public static function detailsRoom($room) {
return $room->getName() . " Dimensions: " . self::displayDimensions($room->getDimensions());
}
First we use the getName
method on the Room
object that was passed in. Then we do a bit of concatenation for the " Dimensions: "
part, and one more concatenation. This time, we're calling the displayDimensions
which is a method in the same class and because it's static, you will need to use self::
here. Then we pass in the dimensions that were returned from the Room
object's getDimensions
, which should be an array with two numbers.
Hope this helps!
Josh Coast
5,112 Points@Jennifer Nordell Just a note, there's a typo in the question on the test.
"The $room object will have the follow methods:" should be "following"
Jaroslav BÃlek
9,415 PointsJaroslav BÃlek
9,415 PointsThe introduction in this form is much more human than the original one. Thanks
Josh Coast
5,112 PointsJosh Coast
5,112 PointsThanks Jennifer Nordell, they should have stated the question that way! It's so vague to me as a novice. Like Jaroslav, I thought I had to write the other class and objects.