Skip to main content
🟨 JavaScript Foundations

Functions

A function takes inputs (arguments) and returns an output. They're how you package up logic to reuse it.

function double(n) {
  return n * 2;
}
double(5); // 10

Your task

Write a function add that takes two numbers and returns their sum.

⚑ 25 XP

🧱 Code blocks

Drag a block into the editor, or tap it to drop it in where your cursor is. Add them in order to build your answer.

solution.jsRuns in your browser
Loading editor…
Tests3 to pass
add(2, 3) === 5
add(-1, 1) === 0
add(10, 20) === 30

Run your code to check these.