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 trialChristopher Gregory
4,183 PointsCreating Reusable code with functions
Can someone tell me what I am doing wrong please?
function returnValue(name) {
return(name)
}
returnValue('Christopher')
var echo = returnValue
<!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>
3 Answers
huckleberry
14,636 PointsYou don't need to have the () around the return value, just a space.
so... here
function returnValue(string){
return string;
}
var echo = returnValue('any text here')
Ayoub AIT IKEN
12,314 Pointsfunction returnValue(name) {
return(name);
}
var echo = returnValue('ayoub');
Ayoub AIT IKEN
12,314 Pointswhen you have a method that hs a return, you have to put it into a variable and you have to call it and specify the argument between prentecies, if it is a string argument, you put it inside ' ', if it is a number you write as it is.
Christopher Gregory
4,183 PointsCheers dude! Super helpful :) Thanks for explaining, i think ill go back and rewatch a few videos