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

Jason Kang
Jason Kang
2,749 Points

After your newly created returnValue function, create a new variable named echo. (Need help with this challenge task)

Instructions: 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.

What am I doing wrong?

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

11 Answers

Hey Jason,

This is how it should look:

function returnValue(ferociousAnimal) {
  return ferociousAnimal;
}

var echo = returnValue('Red Fox');

You were supposed to create a new variable called echo after the function. If it's still not clear, feel free to ask again.

I don't quite understand how the value of returnValue became 'Red Fox'. How did that get introduced?

Hey Rachael,

The value 'Red Fox' is arbitrary; it could have been any thing else — like 'asdfsf' — and it would still work. That is, the value of echo would still be whatever was passed to the returnValue() function. Did that answer your question?

Alan McClenaghan
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alan McClenaghan
Full Stack JavaScript Techdegree Graduate 56,501 Points

Great example Makis. If the instructions for the challenge had been this logical rather than just "you can name it anything", I might have been able to see the connection with what they were trying to do and get there without looking for help. Thanks.

Thank you, i've been stuck one hour with it, now it make sense :)

Thanks, Mikis, this was very helpful!

Joseph Torres
Joseph Torres
6,282 Points

I think this was a dumb challenge!!!

Kalle Jungstedt
Kalle Jungstedt
4,709 Points

Is it just me? I cruised thru Html and Css so far....but JS keeps me on my heels. No matter how much a practice every task fells like I´m going in to a test that I haven´t prepared for at all. I do stuff i answer the questions almost alway correct but when it comes to creating some code on my own....I feel completely lost most of the times.

Need some encouragement here! :I will it ever feel easier at all?

Alan McClenaghan
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alan McClenaghan
Full Stack JavaScript Techdegree Graduate 56,501 Points

I feel your pain. Since I started to learn web development, I've discovered that HTML and CSS are just the tip of the iceberg. Every time I feel like I've understood an aspect of JavaScript, it turns out there's even more to learn about it, like another peak to climb.

Kalle Jungstedt
Kalle Jungstedt
4,709 Points

do you have any suggestions on how to go about it? I have started over my JS course 2 times but feel just the slightest improvement. And I get stuck at the same place anyway...

By learning Html and Css here I know they structure everything really well here... but feel like I just don´t get it...and it puts me down to start over and feel basically no improvement when I get back to where I was when I decided to start over, to "get it"... :/

Alan McClenaghan
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alan McClenaghan
Full Stack JavaScript Techdegree Graduate 56,501 Points

Hi Kalle, I note from your profile that you've been a user since the end of August this year. A little over 2 months. That's not long for such an in-depth subject. I've been over the JavaScript material several times and I keep picking up new things all the time and I'm still far from confident about using it. It's a bit like learning a foreign language in that not only do you have to learn the syntax and grammar but you also have to use it regularly to develop the ability. You can't expect to write a great work of literature straight away. Copying out code can only get you so far. You need to be creating your own material. It was a foreign language you'd start off with a sentence or two before building up to more challenging material.

Some things I struggled to grasp the first few times: Different methods for accessing data in arrays and objects Passing data into functions (as above) and getting it out again.

Try posting a similar question directly to the Community and see if someone wiser and more experienced than me can offer you some wisdom. I'd be interested in reading about that too!

my answer:

function returnValue(online) { return online; } var echo = returnValue( 'up' ); returnValue( '' );

Rafal Kita
Rafal Kita
5,496 Points

Similar to the answers above. Here's my version - though I have to admit it took some time before I figured it out on my own.

function returnValue(abc) { return abc; } var echo = returnValue('alphabet');

I dont understand how everything is related. what is the reason for the repetition? I dont even know what question to ask. :(

u suck torres

yarik kes
yarik kes
4,364 Points

u suck too noah

Nicholas Wallen
Nicholas Wallen
12,278 Points

I don't understand this. Does the string you pass somehow override the "ferocious animal" thing?

ian truong
ian truong
4,685 Points

i may not the best person to explain this but ill give it a try. example: function returnValue(). returValue is like a variable in terms of naming. u can call it anything you want 'preferable related to the subject'. inside the parameter, again its like a value or varible u can put any name u want. think of the parameter as a empty canvas. infact lets call it returnValue(emptyCanvas). when u return the emptyCanvas you can put a picture of anything you want in it. console.log(returnValue("landscape"));

correct me if i am wrong. i am trying to understand and learn this myself.

Tomáš Komprs
Tomáš Komprs
14,057 Points

This was really bad challenge..Thanks for help

thnx this post hehe. i tried it and it works :)