JSFiddle - React, Tailwind, and code Playground

by DustyWhite

HTML

Add numbers (in a list or "ARRAY"), and then calculate their average.

JavaScript

//DS: Start with a list of grades (data pool to work with)
var grades = [80, 77, 88, 95, 68];

//DS: Now we need to ADD all of these together and have a variable that represents the sum ("total")
var total = 0;  // TOTAL sonds like it should be a .js keyword

//DS: Here comes mister loop! Start at index 0 and go through each (index numbered) item in the list (array).
for(var i = 0; i < grades.length; i++) {

//DS . . . this is where we add the grades to get a running sum (total)
    total += grades[i];
}
var avg = total / grades.length;

//DS: **Entirely optional saftey check to verify math is corrrect: 
console.log(total)

// print out result to the console:
console.log("THESE are the [number of] droids you are looking for: " + avg)

// There is another way to do this but it involves ".reduce" and I am still trying to figure out the Zen of that, and since I am not comfortable with WHY & HOW it works I will not attempt it here.