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

Dimitris Mitsopoulos
Dimitris Mitsopoulos
2,490 Points

how to create a function named returnValue that immediately returns the argument inside the function

Hi all,

i am a bit weirdly stuck in this exercise, it seems i don't quite get how to create a function named returnValue and immediately return its argument. please help

thanks, Dimitris

script.js
function returnValue(5) {
  return returnValue;
}
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

In this case your parameter is 5 so your function would return 5 as in:

function returnValue(5) {
  return 5;
}

However 5 is not a valid parameter name. Choose something that starts with a letter.

Adam Beer
Adam Beer
11,314 Points

You can not use numbers as an argument. You need to enter a letter or a word inside the function(), and inside the function() you can return this letter or word with return keyword. After the function you can call your function and give it pass to the number, string or other things. For example:

function returnValue(k) { -> Second, the function get the parameter. So k = 5.
  return k; -> Third, the function returned k, and k = 5, so return 5.
}

returnValue(5); -> First, you call the function and pass a parameter.

or

function returnValue(string) { -> Second, the function get the parameter. So string = "Hello World".
  return string; -> Third, the function returned string, and string = "Hello World", so return "Hello World".
}

returnValue("Hello World"); -> First, you call the function and pass a parameter.

Default parameters

Hope this help!