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

Jose Esplana
Jose Esplana
12,503 Points

Can someone please show me how to solve this code challenge or show me where's the link

https://teamtreehouse.com/library/javascript-basics/creating-reusable-code-with-functions/create-a-max-function https://teamtreehouse.com/library/javascript-basics/creating-reusable-code-with-functions/passing-an-argument-to-a-function

script.js
function returnValue(x) {
    var echo = x;
    return echo;
}

alert(returnValue('string'));

Q2

function max(number1, number2) {
  if (number1 > number2) {
  return number1;
  }
  else {
  return number2;
}
console.log(max(5,20));
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>

Hey Jose sorry to answer back so late, some other resources I use are freecodecamp.com and codecademy.com

2 Answers

for the first one :

function returnValue(x) { return x; }

var echo = returnValue('string');

The second one you needed a closing bracket for the first part

function max(number1, number2) { if (number1 > number2) { return number1; } else { return number2; } } /here/

alert(max(5,20)); /* and here you needed to use alert() method instead of console.log() */

Jose Esplana
Jose Esplana
12,503 Points

Hi Jamila, Thank you for your help! Do you know any other sites where I can practice more of this problems?

You can practice here: https://codefights.com/

If you're into videogames you can always do this one as well... https://codecombat.com/