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 trialNatalie Atkins
2,569 PointsJavaScript Function: I can't get pass Task 2 of 2. It keeps saying I'm not storing the "echo" variable.
function returnValue(food){ return food; var echo = returnValue( 'My argument' + food); } returnValue(salad);
function returnValue(food){
return food;
var echo = returnValue('My argument' + food);
return echo;
}
returnValue();
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JavaScript Basics</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
4 Answers
Abe Layee
8,378 PointsLet take a look at your code
function returnValue(food){
return food;
var echo = returnValue('My argument' + food);// 'my argument' is food that you passed on to the function. Therefore, the is no need to call it twice.
return echo;
}
returnValue();
it should be like this
function returnValue(food){
return food;
}
var echo = returnValue('My argument' );// this is storing the returnValue() into the echo var
Will Parry
11,985 PointsSo, there are a couple things here. You're calling returnValue() within the declaration of the returnValue() function. You can't do that. Also, in a function, you can only have one return statement.
If the end goal is to have the function return "My argument salad", try this:
function returnValue(food) {
var echo = "My argument " + food;
return echo;
}
returnValue("salad");
Natalie Atkins
2,569 PointsThank you for your help. That didn't help. I think something is wrong with the app that checks for the answer.
Natalie Atkins
2,569 PointsThanks for helping.
Ted Sumner
Courses Plus Student 17,967 PointsWhile there is nothing wrong with using echo as a variable in JavaScript and they may require it in the challenge, I would not make a habit of it. Echo is a key word in PHP. It took me a second to realize that was not an error in JavaScript.
Natalie Atkins
2,569 PointsNatalie Atkins
2,569 PointsThank you so much :)!! I had been muddling over this for a while. I really appreciate your help.