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

Need help with part 2 of Passing an argument to a function

Having a lot of trouble with this challenge. It keeps saying cannot find variable 'Adam'. But this should work, correct? Can anyone guide me towards what this challenge is asking for? Thanks!

script.js
function returnValue(name) { 
  var echo = 'hello' + name;
  return name;
}
returnValue(Adam);
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

Sorry, didn't see you were looking for the answer to part 2. For the second part to this challenge, it should be set up like this.

function returnValue(name) { 
  return name;
}
var echo = 'Hello ' + returnValue('Adam');

The variable has to be defined outside of the function in order for it to be set as the output of returnValue. You can add strings to it here too.

Hope this helps! Dylan

Hey Adam,

you were really close to having this solved! All you needed were quotations around "Adam" to make it a string, JS was trying to take it in as a variable and causing errors.

function returnValue(name) { 
  var echo = 'hello' + name;
  return name;
}
returnValue("Adam");