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

Chris Harkin
Chris Harkin
1,104 Points

Passing an argument to a function. Challenge takes 2 of 2

Hi am stuck on the Passing an argument to a function. Challenge takes 2 of 2

After your newly created returnValue function, create a new variable named echo. Set the value of echo to be the results from calling the returnValue function. When you call the returnValue function, make sure to pass in any string you'd like for the parameter.

This my solution but it fails on the last line of code with the error

"Oops! It looks like Task 1 is no longer passing."

function returnValue(make) {
  var cars = make;
  return make;
}
returnValue("Ford");
var echo = returnValue("Your car is a " + make);

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Keep in mind that challenges want you to follow instructions to the letter. Here you're doing a little more than they are asking for. First, inside of your function you create a variable named "cars" which you never use again. Secondly, you call the returnValue function not once but twice. The first time it returns "Ford" but is never applied to a variable as a value. The second time you call it it tries to send the string "Your car is a " plus a variable named "make" which doesn't exist in this scope. Remember that make only exists inside of the function while it is being executed. Here was my solution. Hope it clarifies things!

function returnValue(anything) {
  return anything;
}

var echo = returnValue("Write anything here!");
Chris Harkin
Chris Harkin
1,104 Points

Thanks I think I was trying to do more than what they wanted. May a be a bit cheeky and ask if you could help me with another question I posted on here. Please see the link below if you can help. Also if I want to reply/tage directly to someone on a page like this do I just use there name or do it like twitter e.g @lennard hofstader

Carlos Federico Puebla Larregle
Carlos Federico Puebla Larregle
21,074 Points

You don't need to create a variable inside the function scope, you just return the parameter right away like this:

function returnValue(arg_value) {
  return arg_value
};

And for the task number two you have to create a variable named "echo" and assign to it the return value from our function, just like this:

function returnValue(arg_value) {
  return arg_value
};

var echo = returnValue("Any string in here");

I hope that helps a little bit.

Chris Harkin
Chris Harkin
1,104 Points

Thanks I think I was trying to do more than what they wanted. May a be a bit cheeky and ask if you could help me with another question I posted on here. Please see the link below if you can help. Also if I want to reply/tage directly to someone on a page like this do I just use there name or do it like twitter e.g @lennard hofstader