Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics (Retired) Creating Reusable Code with Functions Passing an Argument to a Function

Problem with understanding the Return.

The question in one of the challenges asks to create a function named returnValue and pass it any argument and return immediately. To which my response is

function returnValue(drink){ return drink; } This passes the test

Then when the challenge asks to create a variable named echo and store the result of calling the function returnValue. To this my response is

function returnValue(drink){ var echo = alert('Please get me a ' + drink); return echo;}

returnValue(coffee);

At this stage the it says the 1st Task is not passing. I am not able to understand where am i going wrong. Is there something wrong that i am doing in understanding the basics. Please help.

script.js
function returnValue(drink){
  return drink;

}
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>

1 Answer

Antti Lylander
Antti Lylander
9,674 Points

for task 2, do exactly what the instructions say and nothing else:

Challenge Task 2 of 2 After your newly created returnValue function, create a new variable named echo. Set the value of echo to be the results from calling the returnValue function. When you call the returnValue function, make sure to pass in any string you'd like for the parameter.

I bolded some important words there. You only need one short line for the second task. It is much simpler than what you have written. First off, do not declare the function again. You need to declare a variable and assign a value to it.

Hope this helps. The solution is not that difficult. :)