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

isn't the var already set? for the second part?

isnt' the echo variable already set to return like it asks? this is the second part?

script.js
function returnValue(echo) 
{

 return 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

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

Hi there, Kim Dallas ! I received your request for assistance. Yes, the variable echo is already set, but only inside the function. You've chosen to name your parameter echo, but you could have named it any valid variable name. I believe this is what is causing your confusion. When we call the function, whatever we send in will be assigned to that parameter name and then immediately returned. But the challenge is asking for a variable outside the function to be named echo and it to be assigned the result of calling the function.

We could have done this:

function returnValue(myVariable) {
  return myVariable;
}

var echo = returnValue("Whatever you like here");

When we call the function, we are sending in the string "Whatever you like here". That will now be assigned to the function variable myVariable. The reason I say "the function variable" is because once the function ceases execution, that variable no longer exists. If you were to try and console.log(myVariable); outside the function, you would get an error.

Then we immediately return the value stored in myVariable. This will be returned to the place where we originally called the function which is the right side of the assignment operator after var echo. Remember, the right side of an assignment happens first.

Hope this clears things up! :sparkles:

Adam Beer
Adam Beer
11,314 Points

You are so close. Just a tip. Just relax and go ahead.

  1. Open the google and write into -> save function into the variable javascript
  2. Check the second hit (W3Schools). And read the content.

Reminder: If your question doesn't solved, please don't create a new topic until your question resolved.

I tried that but it's not working past the first part. it keeps saying something is missing