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
Warren Johnson
6,870 PointsCode Challenge: Reviewing PHP Basics (item #2 of 3) - "Enhancing a PHP Application"
I am stumped over this one: have tried SEVERAL variations of the code, and still "no enchilada". Can I get a hand on this one??? (This item is a review on functions)
3 Answers
Elliott Frazier
Courses Plus Student 9,647 PointsIf you show your code we'll be able to help.
Martina Carrington
Courses Plus Student 15,807 Pointsi am having difficult time to solver this problem on task challenge 2 to 3 <?php include("flavor.php");
var $flavor;
function get_flavor(); { return $flavor }
$flavor=get_flavor(flavor);
echo "Randy's favorite flavor of ice cream is ____.";
?>
Brandon Beard
9,495 Points<?php
require('flavor.php');
$flavor = get_flavor();
echo "Randy's favorite flavor of ice cream is ____.";
?>
Michael Stopa
14,965 PointsHi, can Teamtreehouse please fix this exercise?
Warren Johnson
6,870 PointsWarren Johnson
6,870 Pointswell, do you just return the variable (ie., return $flavor;), in the body of the function?? Even though there are no arguments passed into the constructor?? Moreover, OUTSIDE of the function, do you THEN set the return variable ($flavor) equal to the function (get_flavor)? Without an explicit value??
Elliott Frazier
Courses Plus Student 9,647 PointsElliott Frazier
Courses Plus Student 9,647 Pointsthe function was is probably written like this:
<?php function get_flavor(){ return "Cookie Dough"; } ?>
and when you want to call it to action you do this:
<?php get_flavor(); ?>
but in this challenge they want you to call the function get_flavor and store it's return value in a variable called flavor. Here's a hint:
<?php variable = function; ?>
Elliott Frazier
Courses Plus Student 9,647 PointsElliott Frazier
Courses Plus Student 9,647 Pointsthe function was is probably written like this:
<?php function get_flavor(){ return "Cookie Dough"; } ?>and when you want to call it to action you do this:
<?php get_flavor(); ?>but in this challenge they want you to call the function get_flavor and store it's return value in a variable called flavor. Here's a hint:
<?php variable = function; ?>Warren Johnson
6,870 PointsWarren Johnson
6,870 PointsThanks Elliott, For some reason, somethings still not quite there....However, I did set my return value equal to the function as you illustrated, and that seemed to steer me in the right direction. Thanks for your time and effort.
Elliott Frazier
Courses Plus Student 9,647 PointsElliott Frazier
Courses Plus Student 9,647 Pointscould you display your code so I can have a better idea upon how to diagnose the problem.
Warren Johnson
6,870 PointsWarren Johnson
6,870 PointsCode challenge #2:
The flavor.php include file contains a function named get_flavor. That function receives no arguments, and it returns a piece of text as its return value. Call that function and assign the return value to a variable named flavor.
My code:
<?php include("flavor.php");
var $flavor;
function get_flavor() { return $flavor }
get_flavor(flavor);
echo "Randy's favorite flavor of ice cream is ____.";
?>
Elliott Frazier
Courses Plus Student 9,647 PointsElliott Frazier
Courses Plus Student 9,647 PointsOkay I copied your code and numbered the lines of code so I can reference to them easily. Your code:
Mistake on Line 3: you did "var = $flavor" but in PHP you don't need to add "var" before setting a variable like you do in Javascript.
Mistake on Line 5: when you included the "flavor.php" file on line 1 it already included the function, making the code on line 5 unnecessary.
Mistake on Line 7: what you put inside the parentheses in a function is taken as a argument, which is what you don't want to do.
Have you taken the "Build a Simple PHP Application" course yet?
Warren Johnson
6,870 PointsWarren Johnson
6,870 PointsYes. As a matter of fact, I just finished that course, and moved on to this course (next in the series). Ok. I just figured it out. For some reason I'm "looking" past the obvious:
Mistake on Line 5: when you included the "flavor.php" file on line 1 it already included the function, making the code on line 5 unnecessary.
Thanks once again Elliott!
Elliott Frazier
Courses Plus Student 9,647 PointsElliott Frazier
Courses Plus Student 9,647 PointsNo problem! I'm glad you have it figured out.