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 trialNana Ackah
Courses Plus Student 1,935 PointsI can't get my head around this any help
I know it's pretty easy, but I somehow can't understand
function returnValue(dollars, sound) {
var money = dollars;
var echo = sound;
return (money, echo);
}
<!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
Adam Beer
11,314 PointsChallenge Task 1 of 2
Create a function named returnValue that accepts a single argument (you can name it anything), then immediately returns that argument.
This isn't that useful of a function, but we want to make sure that you know all of the important parts of creating a function that can accept parameters when it is called, before moving on to bigger functions.
function returnValue(parameter){
return parameter;
}
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.
The function will accept the string you pass to it and return it back (using the return statement). Then your echo variable will be set with what is returned, the results.
function returnValue(parameter){
return parameter;
}
var echo = returnValue('Hello');
I hope you understand the solution. Hope this help.
mryoung
4,156 PointsI’m still learning javascript too, so this is practice for me...
You’re wanting to make a function and then call it...so:
FunctionName (parameter)
Return it (arguments to fill parameters)
I think that’s the basic layout you’re looking for. The result won’t mean much, but it’s supposed to be basic to help make sure you understand it.
Edit:
The second part is just making a variable, placing it into the function, and then returning it, spitting it back out.
Adam Beer
11,314 PointsThe quiz asks you "accepts a single argument" but you give 2 arguments. Yes, the second part is just making a variable, place it in to the returnValue() function, and give it to one argument.
Step by step. That's how it would run the code.
//Second step: "Hello" will be this argument.
function returnValue(parameter){
//Third step: return "Hello".
return "Hello";
}
//First step: Saved the returnValue() function in the variable.
var echo = returnValue('Hello');
//Fourth step: If you use for example console.log(echo) and gave inside the "echo" variable.
//Fifth step: The output. Logged out the string value.
Hello