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 trialAlec Burger
2,968 PointsIn Localhost possible, in Code Editor Treehouse not.
Hi guys!
Because it has just been released I tried it out and everything worked fine for me except for this code challenge. The Treehouse Code Editor kept saying that it wasn't write while everytime I tried it out in my localhost (Wamp) it worked fine! So my question to you is how to let the Code Editor get it since it actually already works.
This is the code that works on my Localhost, but not in Code Editor of Treehouse (because of the most stupid syntax highlighting method ever I put it on jsbin (Sorry Treehouse, I love you!))
http://jsbin.com/yogiyexi/3/edit
Please tell me what the Code Editor will allow! Thanks in advance!
Alec Burger
2,968 PointsHi Sean Gaffney, I do exactly what you're saying and what Andrew explains but everything gets mixed up. I start the ``` part, but only after 6 sentences of code it started to work (?!).
3 Answers
Derrick Lee
7,743 Pointsclass Fish {
public $common_name;
public $flavor;
public $record_weight;
public function __construct($name, $flavor, $record) {
$this->common_name = $name;
$this->flavor = $flavor;
$this->record_weight = $record;
}
public function getInfo() {
return "A ". $this->common_name ." is an " . $this->flavor . " flavored fish. The world record weight is " . $this->record_weight . ".";
}
}
$bass = new Fish("Largemouth Bass", "Excellent", "22 pounds 5 ounces");
echo $bass->getInfo();
?>
Take note on the return in the method and the echo
Alec Burger
2,968 PointsOh that's it... In just the English language return means that you have to show something and it didn't ring a bell for me that I had to use the return function. Thanks!
Derrick Lee
7,743 PointsHaha, actually you're right, it does mean to "return something".
You call the function $bass = $this->getInfo();, this will invoke the method and the method will start processing. Once it is done processing, it has to return the processed information back to where you call the method which is from $bass. Now you have the processed information in $bass, but you have to echo out the results, that's when the echo comes in.
Alec Burger
2,968 PointsThank you all guys. Just want you to know that I finished the OOP php track!
Sean Gaffney
Front End Web Development Techdegree Student 2,560 PointsSean Gaffney
Front End Web Development Techdegree Student 2,560 PointsHey Alec, is the syntax highlighting here in the forum insufficient? Or are you talking about the syntax highlighting elsewhere?
For the forum, you can specify the language you'd like the syntax highlighting to use by using backticks. Andrew explains it in the "Tips for asking questions" video in the sidebar on the right, but here's the gist:
Which would produce this:
<?php echo("Hi!"); ?>