Add two numbers
Skills: Functions · Numbers
Task
Complete add(a, b) so it returns the sum of a and b. Printing the result is not enough: the tests call your function and look at the value it returns.
Decimal results count as equal when they differ by less than 0.000000001, because computers store most decimals approximately.
Examples
Run examples tries these. Check solution also runs 3 more tests.
- Adds two whole numbersExample
- Call
- add(2, 3)
- Expected
- Returns 5
- Works with a negative numberExample
- Call
- add(-4, 10)
- Expected
- Returns 6
Every test, including the extra ones, is part of this page. Nothing is hidden or secret.
Your code
Loading the editor…
function add(a, b) {
// Return the sum of a and b.
}
Ctrl + Enter (⌘ + Enter on a Mac) runs the examples; add Shift to check. Tab indents; press Esc, then Tab, to leave the editor.
Run examples tries your code on the examples and records nothing. Check solution runs every test and saves an attempt.
Tests
Run your code to see which tests pass.
Console
What your code logs with console.log appears here.