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 trialMichael Stambulyan
3,220 PointsStuck ! cant figure this one out, please help.
how do I add a Variable to this function ?
function returnValue(hello) {
var echo = "returnValue(hello)"
return hello
}
<!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>
4 Answers
Michael Stambulyan
3,220 Pointsthanks for the help :) the task im trying to do is ...... "Now that you've created the returnValue function, call it, by passing it a literal string value -- a series of characters in quote marks like this: 'My argument'. Store the results of the function in a variable named echo."
Colton Ehrman
Courses Plus Student 5,859 PointsYou are missing semicolons
Not sure what your trying to do here var echo = "returnValue(hello)" but this will assign a string "returnVale(hello)" to the variable echo and then you never even use your variable
You return hello, which basically means your functions does nothing but spit back out what you passed it
jaredcowan
11,808 PointsWell, for one, you're forgetting to put the semi colon ;
after you assign the variable and it looks like you're trying to interpolate in a string and call the function on its self, both of which will not work. I think you were meaning to use console.log();
.
You can define variables in these ways.
function returnValue(hello) {
var echo = console.log(hello);
var warn = console.warn(hello);
var error = console.error(hello);
}
or you can define the variables like this:
function returnValue(hello) {
var echo = console.log(hello), // separate variable definitions with a comma
warn = console.warn(hello),
error = console.error(hello); // Only the last defined variable needs to be closed with semicolon
}
Hope this helps you.
Michael Stambulyan
3,220 Pointsthank you ! that was it, just had to write it outside of the function.
Colton Ehrman
Courses Plus Student 5,859 Pointsno problem :)
Colton Ehrman
Courses Plus Student 5,859 PointsColton Ehrman
Courses Plus Student 5,859 PointsYou had the right idea, but dont wrap ur function name in quotes, just wrap the parameter in quotes, and im assuming it wants u to call it outside of the function, otherwise u would have recursion going on. so try this