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.
Sum Up: Add all numbers.
Count: See how many numbers.
Divide: Sum ÷ Count.
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.
Get a list of numbers.
Sum them up and count them.
Divide sum by count.
Let's translate our algorithm into JavaScript, learning the core building blocks of programming.
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;
}