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

Matt Fried
Matt Fried
10,665 Points

Am i missing something? I cannot pass task 2 for the life of me...

I first went with my first instinct of placing the var echo = result; inside the function, then calling the returnValue("This is a test") after the function. But no dice.

Then i tried multiple various combinations like placing the var echo outside of the function, etc, to see if that would work, but nothing. I've run out of ideas, and I almost feel like I'm not understanding the question properly because I don't know what else I could be doing wrong.

Help please.

script.js
function returnValue(result) {
  var echo = result;
  return result;
}

returnValue("This is a test");
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

Matthew Long
Matthew Long
28,407 Points

Your second idea was correct. You're supposed to create the variable echo "after" the function as described in the challenge. The wording may be a little confusing.

function returnValue(result) {
  return result;
}

var echo = returnValue("This is a test");