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

Not getting it.

Again having issues. Not getting functions. =(

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

function returnValue (thisIsAnArgument) {
  return thisIsAnArgument
}

var echo = returnValue('Something')

the text after 'function' is the name of that function

this function return whatever argument we pass to it

we have to define echo outside of this function

we assign echo to the returned value of whatever we call the 'returnedValue' function

Hope this helped!

this does help. Is it normal to have so many questions about javascript? I feel i'm not retaining all the info I'm getting.

Keep coding! Don't worry about learning everything today, it's a long process to conceptually wrap your head around all the rules and quirks. I suggest reading MDN documentation

Read the documents slowly and try to understand everything that's happening Mozilla Developer Network

I also suggest using sites like this below to really expose yourself to problems you wouldn't have though of that you have to figure out to complete. You can also look at other programmers solutions for different approaches. Codefights

let me know if I can ever help with anything! Dan

thank you so much.. I'll check it out. Even if it doesn't help (I'm sure it will), it makes things better that everyone has such good support from each other