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

Isaac Minogue
Isaac Minogue
3,543 Points

What have I done wrong? It's working in the console, but it says it's wrong in the coding challenge...

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

console.log(returnValue( "My argument" ));
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>

4 Answers

Michael Fish
Michael Fish
7,804 Points

In order to complete the challenge you need to store the returned value inside the echo variable like this:

Replace this: console.log(returnValue( "My argument" ));

With this: var echo = returnValue("My argument");

Isaac Minogue
Isaac Minogue
3,543 Points

Thanks so much! What a prompt reply. Really appreciate it. I get it. So, i've already declared the echo variable, but in order to store it, it needs to be placed back into again with

echo = returnValue("My argument");

or, just declare it for the first time outside with

var echo = returnValue("My argument");

is that right?

Chur

John Simoneau
PLUS
John Simoneau
Courses Plus Student 8,105 Points

I have passed all the other challenges pretty easy. This one I have been stuck on for HOURS! I've rewatched videos. Used their codes. Verified things I was doing was valid in a console test, etc. I'm not sure if it's how they are wording it or what but the thing does not work as expected in my opinion. I'm going to try to figure out what's suggested above. Hope it works :)

John Simoneau
PLUS
John Simoneau
Courses Plus Student 8,105 Points

Ok, so this worked on the first part of the challenge

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

I was doing something along these lines

function returnValue( parameter ) {
  var echo = "This is my test " + parameter + " just to see if it works";
  return echo;
}

Which won't pass. I guess I overcomplicated it for whatever verifies the answer provided. Thanks for the help!

Isaac Minogue
Isaac Minogue
3,543 Points

Are you on task one or task two?

I think yours does work, (like mine did, and you can test it by using console.log(returnValue( "Something" ) ); but it's just not the answer the challenge is looking for.

Michael Fish's answer worked for me – perhaps give that a go? Let me know if it that works!

John Simoneau
John Simoneau
Courses Plus Student 8,105 Points

Yes, I do have both working after reading this. I'm just jabbering incase others have the same problem in the future I suppose :) Glad you posted this question though because I'd still be sitting here trying to figure out the issue...LOL.

John Simoneau
PLUS
John Simoneau
Courses Plus Student 8,105 Points

I didn't realize you might have been on the second part of the challenge when posting this. I'm not sure naming the var "echo" for the first part of the challenge or inside the function itself is the best way to go. Then you have to create a var at the bottom named echo to complete the 2nd part of the test which makes it look pretty confusing. In my very inexperienced opinion it would be better to name the var and the return that is displayed inside the function something else and save the echo for the var at the bottom. If that makes sense...

Michael Fish
Michael Fish
7,804 Points

I agree with you John it is worded a bit funny. Overall I think Dave does a really good job but IMHO it should tell you that the # needs to be stored in a variable as it is confusing for us newbies. Stick with it though this was my first 'Best Answer' and it was very rewarding. Thanks Isaac!