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

Luis Paulino
PLUS
Luis Paulino
Courses Plus Student 1,779 Points

Like this?

I edited this answer, but I know something still f# up.

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

4 Answers

Hi Luis,

You are close, but currently you are assigning a string of 'returnValue();' to the variable echo, instead you want to call the function and provide a string as the argument, the return value of the returnValue() method will then be stored in the variable.

function returnValue(anything) {
  return anything;
}
var echo = returnValue('string here');

Hope that helps

KB :octopus:

Steven Parker
Steven Parker
231,072 Points

There should have been a hint with the challenge test response. Did you get this response:

Bummer! It doesn't look like you passed a string (characters inside quote marks) to the returnValue() method like this: returnValue('hello').

Also, the quotes they put around the answer aren't meant to be part of the answer. So your actual answer would look something like this:

var echo = returnValue('hello');

You're welcome :octopus:

Russell Sawyer
seal-mask
.a{fill-rule:evenodd;}techdegree
Russell Sawyer
Front End Web Development Techdegree Student 15,705 Points

You are pretty close. You need to pass a string into the function. Also, when you call the function you don't use quotes.

function returnValue (anything) {
  return anything;
}
var echo = returnValue('string');