From Concept to Code

Your interactive journey into averages, algorithms, and JavaScript.

The "average" (or mean) is a single number that summarizes a group of numbers. It gives you a sense of the typical value in the set.

The 3-Step Recipe for an Average

1.

Sum Up: Add all numbers.

2.

Count: See how many numbers.

3.

Divide: Sum ÷ Count.

Interactive Calculator

+ +

Calculated Average:

90.00

(80 + 90 + 100) / 3

An algorithm is a blueprint for solving a problem. It’s the step-by-step logic we create before writing a single line of code.

Input

Get a list of numbers.

Process

Sum them up and count them.

Output

Divide sum by count.

Let's translate our algorithm into JavaScript, learning the core building blocks of programming.

Your Turn to Code!

Fill in the missing line in the function below to complete the average calculation.


function calculateAverage(numbers) {
  let sum = 0;

  for (let i = 0; i < numbers.length; i++) {
    sum += numbers[i];
  }

  // YOUR CODE HERE: Calculate the average
  

  return average;
}

Output: