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

Help pls

I tried 20 mins and still.....

script.js
function returnValue( Hello ) {
 var randomNumber = Math.floor( Math.random() * upper)+1;
}
randomNumber(6) ; 
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>

Hey Dragos,

You need to assign the output of randomNumber to a variable. Also, the argument must be a string.

function returnValue(number) {
  return number;
};

var echo = returnValue("6");

-Ben

2 Answers

Todd Anderson
Todd Anderson
4,260 Points

Hi

In your code I see you passing in a parameter of Hello. What is that? Is that another class you have somewhere not shown in your snippet?

Also, just putting randomNumber(6) is going to give you an error because that variable only exists inside the method returnValue(). If you want to call your function you will do so like

returnValue(6);

However, since you aren't excepting an int and are instead excepting hello this will also not work until you fix that.

For this challenge they want you to just return what is passed in...

function returnValue(str){
    return str;
}

then set the return value of that function to a variable named echo, putting your own example of the same type being passed in, i used str, so I called my function passing in the string "example".

var echo = returnValue("example");

I hope this helps.

SAMUEL LAWRENCE
SAMUEL LAWRENCE
Courses Plus Student 8,447 Points

Hi guys I'm having the same issue here. My biggest problem is I don't understand the question the way it's written. The first part of the challenge I get it correct.

function returnValue( drink ) {
  return drink;
}

The second part is where I'm getting stuck. What exactly does he mean when he says " >Set the value of echo to be the results from calling the returnValue function. what is the results from calling the returnValue? and I read some of the replies I still don't get it. I already spent an entire day trying to figure this out. Here is the second part of my code.

function returnValue( drink ) {
  var echo = returnValue("drink");
  return drink;
}

returnValue('water');

When I put this it says question 1 is no longer passing. Or there was a communication error appears. When I run this code in my coding app and few it on a webpage it says there is a recursion error. I'm really stuck.

if I change the code to this

function returnValue( drink ) {
  var echo = "drink";
  return drink;
}

returnValue('water');

it says Bummer! Hmmm. It doesn't look like you're storing the returned value in the echo variable.

SAMUEL LAWRENCE
PLUS
SAMUEL LAWRENCE
Courses Plus Student 8,447 Points

Hey guys I figured it out. I was putting the echo variable inside the function which wasn't what he asked. The question was a bit unclear cause it didn't say if is to put in inside or outside the function and since in the examples in the video he was always putting the variable inside the function I just assumed. But I guess it's my fault too cause you know what they say > when you assume you make an ass of u and me. ass-u-me. I had it right all along just not in the right place.