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

Rebekah McCarley
Rebekah McCarley
1,835 Points

How do I complete step 2 of this challenge?

I can't seem to figure out step 2 of this challenge. I've tried a bunch of different things and keep getting the same error -- that I'm not storing the return value in the echo variable. Can someone please review my code and tell me where I'm going wrong? I'm completely lost on this one.

script.js
function returnValue(greeting) {
  return greeting;
  var echo = 'greeting' + ' there!';
}

returnValue('Hello');
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

Steven Parker
Steven Parker
231,269 Points

After step 1, the function is complete. In step 2 you won't make any changes to the function, but you'll add code after the function to create the variable, and to set it using the function.

Ryan Colquhoun
Ryan Colquhoun
12,026 Points

Hi Becky,

Your answer is close, you just need to arrange the 'return' call line. I've added some code below that hopefully will help. Also, by using quote marks around 'greeting', you're creating an actual string.

function nameGreeting(firstName) {
    //create var string, and concatinate ' is my name.' to firstName
    //firstName doesn't require quotes
    var stringTogether = firstName + ' is my name.';

    //return the final string, with the variable stringTogether
    return stringTogether;
  }

//call the function 
nameGreeting('Becky');


//output is 'Becky is my name.'
Steven Parker
Steven Parker
231,269 Points

These suggestions don't go with this challenge. Perhaps you have this question confused with another part of the course?