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 trialBryan Makle
4,531 Pointseverytime I store the return value inside the variable I receive an syntax error? please assist
function returnValue(hi) { var echo = return hi; }
returnValue('hi');
function returnValue(hi) {
var echo = hi
return hi
}
returnValue('hi')
<!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 PointsInside your echo variable equal to hi but hi is a string so you can use apostrophs before and after string. When you returned the string don't use the variable value you can use variable name. Please check the Syntax. Supplement: Object.values(). Hope this help.
Challenge 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(echo) {
var hi = echo;
return hi;
}
or use the shorter solution
function returnValue(echo) {
return echo;
}
Antti Lylander
9,686 PointsThis was the solution for taks 1:
function returnValue(hi) {
return hi;
}
Instructions for task 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.
So, now you need to declare variable echo
outside the function. Then, on the same line, set its value by calling returnValue and giving any string as an argument.
You also forgot some semicolons.