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

Diyan Aleksiev
Diyan Aleksiev
4,142 Points

I cant pass, have something wrong in this challenge

help

script.js
function returnValue(hui){
var echo
  return hui 


}
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>

5 Answers

Alex Heil
Alex Heil
53,547 Points

hey Diyan Aleksiev , looks like you're mixing the function with the call, let's break them apart and then we'll get it working ;)

so, that's the first part where we declare the function (task 1):

function returnValue(hui) {
return hui;
}

now the second part, here the task wants us to call it and then save it in a variable. I'll break this as well to better explain it:

to simply call the function you would write it like this:

returnValue("My argument");

and to create a variable you would do this:

var echo ;

now bringing both together it will at the end look like this:

var echo = returnValue("My argument");

and with this code the challenge will pass just fine. hope this helps you out ;)

I'm not quit sure what the challenge is asking you to do, but I do see a couple things to comment about. You need semicolons at the end of your declaration and return statements in script.js. Right now the variable echo is not used, so is unneeded, unless you plan on using it later. Lastly, from the code snippet shown, I don't see where the function returnValue is called. It won't run if it's not called. Good Luck!

Diyan Aleksiev
Diyan Aleksiev
4,142 Points

Doesn't pass ...

-Hmmm. It doesn't look like you're storing the returned value in the echo variable.

function returnValue(hui) { return hui; returnValue("My argument"); var echo ; var echo = returnValue("My argument"); }