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

Argument and Return statement

I keep doing what it tells me to do, and every time I do, it changes what i need to do. so I do that and it tells me to do the first task all over again,

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

1 Answer

Task 1: !! DON'T FORGET SEMI COLONS ; IT THROWS ERROR !!

function returnValue(anyThing) {

return anyThing;

}

Task 2: !! CREAT THE NEW VARIABLE OUT FROM YOUR FUNCTION !!

function returnValue(anyThing) {

return anyThing;

}

var echo = returnValue("anyOtherThing"); // USE PARANTHIES BEACUSE AT NOW YOU PASS A STRING TO THE FUNCTION AND NOT A REFERENCE/VARIABLE!

By the way in Your code, You do a recursive function, wich loops forever :)

Have a nice day, Bye!