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

Yolanda Guerra
Yolanda Guerra
3,290 Points

Help with task 2 of 2 under functions. I can not make the function work and am drawing a blank as to the solution.

I have watched the videos but it doesn't help just need a little boost.

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

3 Answers

Sean T. Unwin
Sean T. Unwin
28,690 Points

The var echo line should not be in the function, but outside of it. This variable should equal the results of the function call. The challenge states to, 'Store the results of the function in a variable named echo'. You are also requested to pass a String to the function when it is called.

Beneath the function we need to declare a new variable, var echo, which calls returnValue(), pass in a String as argument, and store the results in the variable.

Passing a String as an argument to a function call needs to be surrounded by quotes, such as, returnValue('This is a String');.

I hope that helps. :)

Zack Klinger
Zack Klinger
17,622 Points

You are missing a couple of semi-colons, ';' after the statements in your function.

Yolanda Guerra
Yolanda Guerra
3,290 Points

Thank ya'll very much just what I needed to get the function to work correctly. Thanks again.