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

Wil Silvestrini
Wil Silvestrini
5,069 Points

How to answer?

I have no idea. Question: 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.

script.js
function returnValue(test){
  return test;
  var echo
}
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

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hi Wil,

You're on the right track. Your function is correct, except you need to remove the 'var echo' from it. The second part of the challenge wants you to "call" the function and store the result in a variable called 'echo.' To call a function is just functionName();

The challenge however, want a string passed into the function call, so your code will look like this:

function returnValue(test){
  return test;
}

var echo = returnValue("Hello");

Hope this makes sense and helps you. Jason :)

Chris Adamson
Chris Adamson
132,143 Points

For this challenge, you don't need a separate html file to invoke the method (having the html file in the challenge is a little misleading):

function returnValue(a) {
  return a;
}

var echo = returnValue("My argument");