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

passing an argument to a function in javascript

even though this is pretty simple, i can seem to get it...any help would be much appreciated

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

4 Answers

You need to define echo outside of the function, not inside it.

var echo = returnValue('apple');
Dustin McCaffree
Dustin McCaffree
14,310 Points

I'm a bit confused by your question, but from the looks of it, you are looking to do this:

function returnValue(number) {
  return number;
}
returnValue(1);

This should return 1 as your number. Is this what you were attempting?

sorry i didn't make this very clear, but i'm confused...i'm trying to get through a code challenge and i'm being asked to create the var echo before calling a function

Double-check the prompt and see my answer -- it wants you to define echo AFTER the function, not before it.

Double-check the prompt and see my answer -- it wants you to define echo AFTER the function, not before it.

thank you for your answers, galen and dustin