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

Charles Ng
Charles Ng
4,444 Points

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
231,269 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");
Charles Ng
Charles Ng
4,444 Points

Thanks man! I was so frustrated.

Cindy Lea
PLUS
Cindy Lea
Courses Plus Student 6,497 Points

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.

Jesus Mendoza
Jesus Mendoza
23,289 Points

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

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

Charles Ng
Charles Ng
4,444 Points

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.