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 trialVytautas Dargis
5,715 Pointsfunction returnValue(str) { var echo = return str; } How to pass and store the results in a var echo?
function returnValue(str) { var echo = return str; }
How to pass and Store the results of the function in a variable named echo.
Now that you've created the returnValue function, call it, by passing it a literal string value -- a series of characters in quote marks like this: 'My argument'. Store the results of the function in a variable named echo.
function returnValue(str) {
var echo =
return str;
}
<!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>
5 Answers
Abe Layee
8,378 PointsIn anthoer word, create a var echo outside the function and pass the function name to it. Something like this. Your code is almost right except that the echo var needs to be outside the function and pass the returnValue() to it.
function returnValue(one) {
return one;
}
var echo = returnValue("My argument");
Colton Ehrman
Courses Plus Student 5,859 PointsOk so all your function is going to be doing is returning something. Outside of your function you need to assign the "call" (returnValue()) to the variable echo. Make sense?
Vytautas Dargis
5,715 PointsIt worked. Thanks!
Abe Layee
8,378 PointsYou're welcome.
Zack Guo
12,135 PointsHere is my solution:
function returnValue(food){
return food;
}
var echo = returnValue("beef");