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 trialSibabale Proffessor Joja
2,750 Pointsreturn a function
Create a function named returnValue that accepts a single argument (you can name it anything), then immediately returns that argument.
The above are instructions for a code and below is how I executed:
function returnValue (){
prompt("What is your name?");
}
return returnValue;
BUT I get an error saying there is a Parse error
function returnValue (){
prompt("What is your age?");
}
return 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>
2 Answers
Sergey Podgornyy
20,660 PointsYou need to return value from function, but don't after function. Your functions always return some values, or perform some code which you can reuse whatever times you want:
function returnValue (name) {
return name;
}
var echo = returnValue('hello');
Sibabale Proffessor Joja
2,750 PointsThanks a mile Sergey!!
Sergey Podgornyy
20,660 PointsYou are welcome