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

Just a little confused

I know this is just basic but I feel like I am going back and forth on what its asking.

script.js
function returnValue(a){
  var echo = 'Curtis' + a;
  return echo;


}

document.write(returnValue('Curtis'));
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

You're close, just need to move some things around.

function returnValue(a){
  var echo = 'Curtis' + a;
  return echo;


}

document.write(returnValue('Curtis'));

First delete document.write.

You're going to want to pass a variable to the function as a variable like

function name(variable)

and return that variable. The next part wants you to pass a string to your function (and have it returned) then assign that returned valued to your echo variable.

var variable = func("some string I pass ing")

It makes sense.....the thing that threw me off was when it asked me to make a variable, I was thinking I was still making up another part of the function. Instead I'm storing it outside the function. Thank you!

Yeah, sometimes the hardest part of working on a problem is figuring out what people are actually asking for.