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 trial

JavaScript JavaScript Basics (Retired) Creating Reusable Code with Functions Passing an Argument to a Function

Marina Klimi
PLUS
Marina Klimi
Courses Plus Student 1,080 Points

I will need feedback and help on my code.

I am trying to write the code for this question but I do not think so I do it right. Please have a look and let me know. "function returnValue ( echo ) { return echo ; alert ( returnValue ); } alert ( returnValue ); var echo = returnValue(alert); " Thanks in advance. Marina

script.js
function returnValue ( echo ) {
  return echo ;
  alert ( returnValue );
}
alert ( returnValue );
var echo = returnValue(alert);
index.html
<!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

Daniel Boisselle
seal-mask
.a{fill-rule:evenodd;}techdegree
Daniel Boisselle
Front End Web Development Techdegree Student 17,438 Points

The remaining code inside a function will not run after a value has been returned, the execution context will close. Therefore calling 'alert' on line 3 will not run.

On your line 6 you need to be passing in a string, but you're passing in the 'alert' function which doesn't make much sense in this case.

Hope this helps!

function returnValue (argument) {
  return argument
} 

var echo = returnValue("Passing in a string argument")

Dan