>_Code Club
← All exercises

javascript

Functions

JavaScript has a classic way to write functions:

function triple(n) {
  return n * 3;
}

...and a shorter one, called an arrow function:

const triple = (n) => n * 3;

Both do the same thing. The curly braces { } mark what's inside the function (in Python it was the indentation).

Your mission

  1. Write a function double(n) that returns n times 2.
  2. Write a function greet(name) that returns `Hello, ${name}!`.

Try one with each style!

Next exerciseArrays and loops →
Loading the editor…