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

I am a bit confused on how to call it and pass it to the function?

Could you please help me with this code challenge? Have been sitting for the past 30 min, cannot write it down :(

script.js
function returnValue() {
 var echo = results;
 return ("My argument"); 
}
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>

1 Answer

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Hi, Rustam Ilyassov .

Here's a simple challenge: create a function named returnValue() that accepts a single argument, then returns that argument.

Here's how to do it

function returnValue(arg) {
  return arg;
}

This question ask you to create a function returnValue, it takes a single argument, arg is argument in the above code. (you can name it anything you want, argument's naming bears no significant meaning, you only give it a name so you can reference it later in the body of the function.) And return the arg in the function body, that's all this question is asking.

Hi William!

Yes i understood that part, but the second part is what i struggle with. Here is the task:

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.

thank you in advance.

William Li
William Li
Courses Plus Student 26,868 Points

Hi, Rustam, I think you perhaps don't completely understand the first part, because your implementation of returnValue is incorrect, it takes NO arguments and doesn't return the right answer.

Ok, onward to 2nd part.

var echo = returnValue('My argument');

The problem asks you to call returnValue function and pass in the String 'My argument' as argument, and assign its return value to echo variable. And that's what the above code does.

oooohhh ok!! Thank you very much William! I got it now! Really helpful!