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 trialsaranyamoellers
31,691 Pointscreate a constructor for Trout class
Please Help? What did i do wrong for the challenge 2 of 5.
<?php
class Fish
{
public $common_name;
$output = "The {$this->common_name} is an awesome fish. ";
$output .= "It is very {$this->flavor} when eaten. ";
$output .= "Currently the world record {$this->common_name} weighed {$this->record_weight}.";
return $output;
}
public $flavor;
public $record_weight;
function __construct($name, $flavor, $record){
$this->common_name = $name;
$this->flavor = $flavor;
$this->record_weight = $record;
}
public function getInfo() {
}
class Trout extends Fish{
function __construct($name,$flavor,$record){
parent::__construct($name,$flavor,$record);
}
}
?>
<?php
class Fish
{
public $common_name;
$output = "The {$this->common_name} is an awesome fish. ";
$output .= "It is very {$this->flavor} when eaten. ";
$output .= "Currently the world record {$this->common_name} weighed {$this->record_weight}.";
return $output;
}
public $flavor;
public $record_weight;
function __construct($name, $flavor, $record){
$this->common_name = $name;
$this->flavor = $flavor;
$this->record_weight = $record;
}
public function getInfo() {
}
class Trout extends Fish{
function __construct($name,$flavor,$record){
parent::__construct($name,$flavor,$record);
}
}
?>
2 Answers
Ryan Duchene
Courses Plus Student 46,022 PointsIt looks like you may have accidentally cut-and-pasted one part of your code into another. Use this to keep going with the challenge. :) Good luck!
<?php
class Fish
{
public $common_name;
public $flavor;
public $record_weight;
function __construct($name, $flavor, $record){
$this->common_name = $name;
$this->flavor = $flavor;
$this->record_weight = $record;
}
public function getInfo() {
$output = "The {$this->common_name} is an awesome fish. ";
$output .= "It is very {$this->flavor} when eaten. ";
$output .= "Currently the world record {$this->common_name} weighed {$this->record_weight}.";
return $output;
}
}
class Trout extends Fish{
function __construct($name,$flavor,$record){
parent::__construct($name,$flavor,$record);
}
}
?>
saranyamoellers
31,691 PointsSorry guys ,I didn't notice your help. Thank you very much. I got it already.
Ken Alger
Treehouse TeacherKen Alger
Treehouse TeacherEdited for markup