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

Billie Barnett
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Billie Barnett
UX Design Techdegree Graduate 17,463 Points

Passing an argument to function

I honestly do not know what I am doing wrong. It keeps stating that Task 1 is no longer passing, but the code is valid.

script.js
function returnValue(money, hours){
  var echo = money * hours;
  return echo;
}

returnValue(10.25, 8);
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

Dale Severude
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Dale Severude
Full Stack JavaScript Techdegree Graduate 71,350 Points

Hi Billie,

For part one you were supposed to create a function to pass in a value and then return the value. Your code is no longer doing that. Once this function is created, you don't have to change the function anymore.

The second part is for outside of the function, to declare a variable, and call the function with a string parameter. You are not passing in a string and are not assigning the function to a variable.

Hope this helps.

Hi Billie, according to the challenge, you're to set the value of the variable 'echo' to be the result of calling the 'returnValue' function, something like this:

var echo = returnValue();

Then later in the challenge you're instructed to pass in any string you like for the parameter(i.e. an argument) when calling the function. All you need do is to return that single parameter you used in declaring the function in task 1 with the 'return' keyword, then call the 'returnValue' function with any string as the argument and finally store it in the 'echo' variable. For example:

function returnValue(text){
  return text;
}

var echo = returnValue('I love coding with JavaScript');