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

kingdavid igbayilola
kingdavid igbayilola
8,678 Points

function

i am trying to allow the variable to store a information but i keep getting the error message

script.js
function returnValue(jupiter) {
   var echo = jupiter;
    return echo;
}
returnValue("jupiter");
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

kingdavid igbayilola
kingdavid igbayilola
8,678 Points

Thanks what about the ( ; ) is it not supposed to be there

Cooper Runstein
Cooper Runstein
11,850 Points

Yes, sorry, it's really good practice to end your lines with semi-colons, in this particular case you actually don't need to, but I typed that out fast and forgot to add them in. It's definitely best practice to have that semi-colon:

function returnValue(arg) //Just don't put one here{
  return arg; //semi-colon here
} //And one here won't do anything

var echo = returnValue("string"); //semi-colon here
Cooper Runstein
Cooper Runstein
11,850 Points

You're trying to do too much in the function, you need to set the variable echo to equal the result of the returnValue function when passed a string of your choosing.

function returnValue(arg){
  return arg
}

var echo = returnValue("string")