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 trialAndy Crofford
9,959 PointsWhat am I doing wrong in this JavaScript code?
I get this message: Bummer! Hmmm. It doesn't look like you're storing the returned value in the echo
variable.
function returnValue( fruit ) {
var echo = fruit;
return echo;
}
returnValue("apple");
<!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>
3 Answers
Bill Hinostroza
19,273 PointsThis is my code and It passes.
var echo;
function returnValue(str){
echo = str;
return echo
}
returnValue("Bill")
Steven Parker
231,236 PointsYou were really close!
Task 2 says: "After your newly created returnValue function, create a new variable named echo. Set the value of echo to be the results from calling the returnValue function. When you call the returnValue function, make sure to pass in any string you'd like for the parameter. "
Notice that it says to create the variable after the function, not inside it.
Just put the function back to the way you had it in task 1, and then crreate and assign the new variable when you call your function.
Andy Crofford
9,959 PointsI tried doing it outside of the function and get the same message.
Tobias Helmrich
31,603 PointsHey there,
Steven actually already gave you the right solution. I just want to add the code so you can see where your problem might be. Bill's code may pass but he's creating the variable outside of the function and is accessing it in the function outside of its scope which probably isn't the best solution for this challenge.
function returnValue(fruit) {
return fruit;
}
var echo = returnValue("apple");
It should work like this, it's just the code for the solution Steven gave you, I hope that helps! :)
Andy Crofford
9,959 PointsAndy Crofford
9,959 PointsOkay, I had that at first, but was declaring the variable in the wrong place. Thanks for your help.