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 not sure I understand their instructions

I am stuck. please help.

script.js
function returnValue(abc) {
  var echo = abc;
  return abc;
 }



returnValue("Hello");
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>

3 Answers

Steven Parker
Steven Parker
241,485 Points

:point_right: The assignment of the new variable "echo" should occur after the function, not inside it.

Leave the function as it was when you passed task 1.

But if that hint is not enough, you should end up with something like this:


:warning: SPOILER ALERT


function returnValue(abc) {
  return abc;
}

var echo = returnValue("Hello");

Thanks man! I was so frustrated.

The thing to remember for challenges is only give them what they ask for. Dont put in any extra lines of code, it is a computer that checks the answers. That being said, they just want you to create a function with one parameter that returns the value that was passed to it:

function returnValue (abc) { return abc; }

This passed the challenge.

Thanks anyway.

When a function returns something, you can store that something in a variable.

var echo = returnValue(abc); will store abc inside the variable echo

I did that and it said "Oops! It looks like Task 1 is no longer passing." That's why moved the "var echo" back inside the function.

Thank you.