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

eugene doolittle
eugene doolittle
3,001 Points

passing a argument

Having problems with this one...

script.js
function returnValue (width) {
     var echo = alert(width);
   return echo;

}

console.log(returnValue(4));
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

Alex Koumparos
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,887 Points

Hi Eugene,

The challenge is asking you to "Create a function named returnValue that accepts a single argument (you can name it anything), then immediately returns that argument." So you shouldn't be creating more variables or performing alerts in the function, just returning the argument (in your case width). Cheers

Alex

eugene doolittle
eugene doolittle
3,001 Points

I thought what you are referring to was the first task. I got through that part. I'm stuck on the second task asking to make a variable name echo and run it through a string.

Alex Koumparos
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,887 Points

Hi Eugene,

OK, well in the second part it is telling you:

After your newly created returnValue function, create a new variable named echo.

You are creating the variable echo in your function, not after it.

Then it tells you:

Set the value of echo to be the results from calling the returnValue function.

When you declare echo after the function, you should be assigning to echo the value you get from calling your function. You are not setting the value of echo to be the result of calling the function, you are logging the result of calling the function.

Finally:

When you call the returnValue function, make sure to pass in any string you'd like for the parameter.

You are not passing in a string, you are passing in a number.

Cheers

Alex