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 trial

PHP

James Preus Jr.
PLUS
James Preus Jr.
Courses Plus Student 8,582 Points

Object-Oriented PHP Basics - Section: Building The Recipe - Code Challenge: Static Answer Help

I am confused on how to solve this Code Challenge. I think I'm making it harder than it is and starting to get myself confused. Here is the question from the Code Challenge:

*Th accepted parameter $room will be an object which has a method named getDimensions. Add a return value to the detailsKitchen method that displays "Kitchen Dimensions: length x width", where length x width is returned from the 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

Below is as what I have in the code editor:

class Render {

  public static function displayDimensions($size)
  {
    return $size[0] . ' x ' . $size[1];
  }

  public static function detailsKitchen($room)
  {
   return "Kitchen Dimensions: " . $room; 
  }

  public function getDimensions()
  {
    return self::displayDimensions($size);
  }  
}

That is as far as I was able to make it without any help. Can someone please help me figure out how to complete this Code Challenge? Thank you!

2 Answers

Hi James You do not need to add the method getDimensions to the Render this is already given by the $room object. Just pass the value to displayDimensions like so.

    public static function detailsKitchen($room){
      $output = "Kitchen Dimensions: ";
      $output .= self::displayDimensions($room->getDimensions());
      return $output;
    }
Simon Coates
Simon Coates
28,694 Points
class Render {
    public static function displayDimensions($size)
    {
      return "{$size[0]} x {$size[1]}";
    }
  public static function detailsKitchen($room){
    return "Kitchen Dimensions: ".self::displayDimensions($room->getDimensions());
  }
} 

update: looks like Ron Szymanski beat me to the punch.