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.