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 trialVanessa Solymosi
1,372 PointsCreate an variable for the next exercice :-/
Create a function named returnValue that accepts a single argument (you can name it anything), then immediately returns that argument.
function returnValue(age) { return age; }
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.
/* pleaaaase, I am blocked whith this code, what is the good code? */
function returnValue(age) { return age;
var echo = age; return returnValue('28'); }
function returnValue(age) {
return age;
var echo = age;
return returnValue('28');
}
<!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
Kieran Barker
15,028 PointsHi, Vanessa! You’re so close!
Your first two lines are correct, but what you’ve then done is create a variable inside the function which would be equal to the age
argument, but would never be returned. You are then trying to return a number as a result of calling the function which you are still declaring. Here’s what you needed to do:
// Create a function that accepts an argument and returns that argument
function returnValue(age) {
return age;
}
// Outside the function declaration, call the function and assign it to a variable
var echo = returnValue(28);
I hope this makes sense! I should also point out that putting 28 in quotes, as you did, would make it a string and not an integer :)
Vanessa Solymosi
1,372 PointsThanks a lot Kieran. One of my answers was that but I put it inside the {} :-/ I knew I had almost the good one but there was a little &/x@ #? stuff missing.