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

passin an argument to a function ,,

please help he is not very clear on what i was suppose to do try d a hundred things

script.js

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

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! I really wish I knew what you'd tried that's failing so that I could better guide you in what you might be missing. Here is a solution and I'll walk you through it:

function returnValue(whatever) {
  return whatever;
}

var echo = returnValue("Return this string please");

Here we declare our function returnValue as required by the challenge. The parameter can be named anything so I chose whatever. Then we immediately return what was sent in by using the return statement.

The second step requires that we declare a new variable named echo. This is also specified by the challenge and must go outside of the function. Otherwise the variable would only belong in the local scope. We then assign the result of passing a string (any string) into our returnValue function. The end result here is that the echo variable will now be set to the string "Return this string please".

Hope this helps! :sparkles: