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

Alan Jaffery
Alan Jaffery
4,803 Points

Challenge - Java Script Basics: Create a function

The Task is: Create a function named returnValue that accepts a single argument (you can name it anything), then immediately returns that argument.

I dont know what i did wrong? Can someone help!?

Thank you and kind regards, Alan

script.js
function returnValue(test){
  return returnValue(test);
}
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>
Antonio De Rose
Antonio De Rose
20,885 Points

I suggest you go through the video again and get an idea, function creation is correct, acceptance of the parameter is correct, the way you return is wrong.

1 Answer

Romain Gaget
Romain Gaget
24,449 Points

You are passing the argument test that you need to return: then if you call the function returnValue('hello') that will return hello

function returnValue(test){ return test; }

Alan Jaffery
Alan Jaffery
4,803 Points

So i dont return the function, i just return the argument?

Thank you for helping :)