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

Tiago Cardoso
Tiago Cardoso
1,329 Points

Storing the returned value

So I was trying to do the second task, and one of the steps is to store the return value to a new varieble named "echo" but I keep getting a error saying that I'm not storing it. Can someone give a little help?

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

Stuart Wright
Stuart Wright
41,120 Points

You need to set the variable echo equal to the value of the result of passing 'Coffee' to your function. You are currently setting echo equal to the result of calling the function without passing anything in. The correct syntax is simply:

var echo = returnValue('Coffee');
Tiago Cardoso
Tiago Cardoso
1,329 Points

Well I changed it but seems that the errors keeps happening, I created the new var in the function after the return method am I doing this right?

Tiago Cardoso
Tiago Cardoso
1,329 Points

Okay nvm, had to be outside of the function mybad thanks a lot man :)