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 trialBrandon Browning
11,989 PointsJavascript Basics(Passing an argument to a function task #2)
Can someone please explain to me what they want when they say that I need to pass a value into the variable echo. Thank you in advance.
function returnValue(hello){
return("hello");
}
returnValue('My argument');
<!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>
2 Answers
Erik McClintock
45,783 PointsBrandon,
They mean that they want you to assign the return value that you get from calling your function to a variable that you create named "echo". Currently, you're just calling your function and not assigning the return value to anything, so nothing happens with that value. Additionally, your return value is returning a string, not the value stored in your argument that is passed into the function, because you've enclosed it in quotation marks.
This is what you're looking for:
function returnValue( myArg ) {
return myArg;
}
var echo = returnValue( 'my argument' );
Notice two things:
1) The return statement is not in quotes, thus you will be returning the value stored in the myArg
argument. In your code, you have return("hello");
, which will always return the string "hello", rather than the value passed into the function
2) I have created a variable called "echo" that I'm assigning the value of my function call to. Thus, we are able to access what our function returns elsewhere (say, logging it in the console for testing purposes or adding it to the innerHTML of another element, for example)
Hopefully this helps to clarify some things!
Erik
Daniel Newman
Courses Plus Student 10,715 Pointsfunction returnValue(hello){
return(hello);
}
returnValue('My argument');
Don't put your hello variable in " ". When you do such way it becomes a string/word variable equal "hello" but not the link to the variable you bypass.