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 Giving Information to Functions

Walter Cortez
Walter Cortez
4,071 Points

Passing an argument to a function...task 2 of 2.

I am having trouble completing task 2 of 2 and system is not letting me snapshot screen. This is what I have wrote it here....what is wrong with this code. Thanks.

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

returnValue("coffee");

3 Answers

Erik Nuber
Erik Nuber
20,629 Points
function returnValue(drink) { 
var echo= drink; 
return drink;
 }

returnValue("coffee");

Outside of the fact that you assign drink to echo and then don't use echo, there shouldn't be anything wrong. The challenges are often very specific.

function returnValue(drink) {  //this is the function start and coffee will be assigned to drink
    var echo = drink;  //drink which stores coffee will be assigned to the variable echo
    return echo;  //echo is returned which stores the value of drink which is coffee.
}

returnValue('coffee');  //this calls the function and sends it coffee

You aren't linked to the challenge itself so I haven't tried it myself. but hopefully this helps you.

Found the challenge... you are to assign echo the value of what is returned so it is just coded slightly differently.

function returnValue(drink) {
  return drink;
}

var echo = returnValue("coffee");
Walter Cortez
Walter Cortez
4,071 Points

Thank you Erik will try this.

The challenge is asking for the variable echo to be defined after the returnValue function. The echo variable will then be assigned the value of the returned value.

function returnValue(drink) {
return drink;
}

var echo = returnValue("drink"); //set echo to the return value of the function
returnValue("coffee"); //call the function with whatever string value you would like
Walter Cortez
Walter Cortez
4,071 Points

Thank you Mindy will try this also!

H Yang
H Yang
2,066 Points

I've had trouble with this challenge because I didn't put quotes around my string that I wanted to pass. Do we always use quotes around strings we pass to a function?

Yes check out the documentation for strings on W3Schools.com http://www.w3schools.com/js/js_strings.asp.

This documentation mentions that strings must be written in quotes for JavaScript to identify it as a string.