CodingNeed.

3 · Work with collections · 8 MIN

Reuse a function

Functions turn inputs into outputs.

A parameter is a local name for an input. Calling a function supplies an argument. return gives the caller a result; console.log only displays something. Small functions with a clear contract are easier to reuse and test.

A small machine takes an ingredient, performs one operation, and gives you a result.

Read the example

function double(n) {
  return n * 2;
}
console.log(double(4));
Check the expected output
8

Your challenge

Return the larger of input.a and input.b. Equal values should return that value.

Common trap

Logging an answer does not return it to a caller.

Next lesson: Keep an ordered list