Skip to content
All challenges
ProgrammingDebugBeginner5 min

Fix the average

Skills: Debugging · Operators

Task

average(a, b, c) should return the average of three numbers: their sum divided by 3. It runs without errors, but the results are wrong. Find the mistake and fix it.

What goes wrong

average(3, 6, 9) returns 12 instead of 6.

Examples

Run examples tries these. Check solution also runs 4 more tests.

  1. The average of 3, 6 and 9Example
    Call
    average(3, 6, 9)
    Expected
    Returns 6
  2. The average of 1, 2 and 3Example
    Call
    average(1, 2, 3)
    Expected
    Returns 2

Every test, including the extra ones, is part of this page. Nothing is hidden or secret.

Your code

Loading the editor…

function average(a, b, c) {
  return a + b + c / 3;
}

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.