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 trialGreg Schudel
4,090 PointsI am unsure of what is being asked.
I am unclear on what is being asked here. What is the correct answer? I have made the following code only to be told that my "task 1 is now not working."
function returnValue(nameItAnything) { var echo = return (nameItAnything); }
function returnValue (nameItAnything){
return(nameItAnything);
}
<!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
Jennifer Nordell
Treehouse TeacherFor this particular challenge the index.html isn't needed or even referenced. They simply are challenging your ability to define a function, pass it an argument, and then return something and assign it to a variable. See my code for clarification:
function returnValue (x) {
return x;
}
var echo = returnValue("Hi there! This can be anything!");
Here I make a function called returnValue and it takes an argument named x. I then immediately return that value. This will not be the case in most functions. Most functions will want you to do something with that information.
Then I make a variable named echo as required by the challenge. I call/invoke/execute the function and send it the string"Hi there! This can be anything". At this point in the function x becomes that string which it then returns. The resulting string is assigned to echo.
David Bath
25,940 PointsDavid Bath
25,940 PointsThe echo variable should be created outside the returnValue function, and needs to pass a string to that function:
var echo = returnValue("something");
The returnValue() function will just pass back the value you sent it (in my example "something").