function createRiver(name, continent, lengthInKilometers) {
return {
name: name,
continent: continent,
lengthInKilometers: lengthInKilometers,
logRiver: function () {
console.log(" The " + this.name + " river is " + this.lengthInKilometers + " kilometers long. ")
},
isLongerThan: function (name) {
return this.lengthInKilometers < name.lengthInKilometers;
}
}
}
var rivers = [
createRiver("Amazon", "South America", 6575),
createRiver("Danube", "Europe", 2850),
createRiver("Ganges", "Asia", 2704),
createRiver("Mekong", "Asia", 4350),
createRiver("Mississippi", "North America", 3730),
createRiver("Nile", "Africa", 6650),
createRiver("Volga", "Europe", 3530),
];
function getAverageLength() {
var total = 0;
for (var i in rivers) {
total += rivers[i].lengthInKilometers;
}
var avg = total / rivers.length; //fix this
console.log(avg)
}
getAverageLength();