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

james mchugh
james mchugh
6,234 Points

stuck on this

I've tried every combination I can think of

script.js
function returnValue(length) {
  return length;
  var echo = (returnValue);
  returnValue(echo + unit);
}
console.log( echo( 20, 'sq ft') )
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

Ben Reynolds
Ben Reynolds
35,170 Points

The echo variable should be declared after the returnValue function, not inside it. echo's value should be the result of calling returnValue with any string passed in.

Ashley, your code works on your test html page because it's valid javascript, i.e. no syntax errors, it's just not performing the operations in the order the challenge is expecting.

OO I get it, you're right my bad.

james mchugh
james mchugh
6,234 Points

I'm still confused. I declared the variable echo outside the function, and I tried to return the returnValue, but it's giving me an error message. I'm really confused. I've posted a new one with my last attempt. Thanks for your help Ben, I'm gradually understanding.

function returnValue(e) {
    var echo = e;
    return echo;
  }

  console.log(returnValue('hi'));

This SHOULD work but on the challenge its not saying it works however when I try it on a HTML page it works fine so I'm not entirely sure