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

JavaScript JavaScript Basics (Retired) Creating Reusable Code with Functions Passing an Argument to a Function

Anthony Birch
Anthony Birch
1,845 Points

How to set the variable "echo" equal to the result of the function call?

How do I set echo = to my argument, which I called "initial"?

script.js
function returnValue (initial) {
  return (initial)
}
var echo;
echo = initial;
index.html
<!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

Emmanuel C
Emmanuel C
10,636 Points

Remember that youre returning "initial" from your function. Try setting your variable equal to the call of your function, that way whats returned is set to your variable. Hope this helps

Hi Anthony, from the challenge you're to set the 'echo' variable to the result of calling the function with a string as an argument. You didn't end the return statement with a semi-colon and you don't need to enclose 'initial' in parenthesis in the return statement. Take for example:

function returnValue (initial) {
  return initial;
}
var echo;
// Using your own name initials as an argument when calling the 'returnValue' function
echo = returnValue('Birch A');

This is the same as storing the string 'Birch A' in the variable 'initial'. Think of a parameter like a variable you store arguments as values in.

var initial = 'Birch A';