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

Creating Reusable code with functions

Can someone tell me what I am doing wrong please?

script.js
function returnValue(name) {
  return(name)
}

returnValue('Christopher')
var echo = 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>

3 Answers

huckleberry
huckleberry
14,636 Points

You don't need to have the () around the return value, just a space.

so... here

function returnValue(string){
    return string;
}

var echo = returnValue('any text here')
function returnValue(name) {
  return(name);
}


var echo = returnValue('ayoub');

when you have a method that hs a return, you have to put it into a variable and you have to call it and specify the argument between prentecies, if it is a string argument, you put it inside ' ', if it is a number you write as it is.

Cheers dude! Super helpful :) Thanks for explaining, i think ill go back and rewatch a few videos