I'm trying to get all the numbers that are higher than the average of a given Array. (this goes into an HTML page so it's with document.write this is what I wrote:
sumAndBigger(arrayMaker());
function sumAndBigger(array) {
for (i = 0; i < array.length; i++) {
sum += array;
}
var equalAndBigger = []
var avg = sum / array.length;
for (i = 0; i < array.length; i++) {
if (array[i] > avg) {
equalAndBigger.push(array[i])
}
}
document.write('The numbers are: ' + equalAndBigger)
}
function arrayMaker() {
var array = [];
for (i = 0; i < 5; i++) {
var entrie = +prompt('Enter a number: ');
array.push(entrie)
}
return array;
}
This doesn't seem to work.. what am I doing wrong here?
Thanks in advance!
sum += array;wat?sumisn't declared, and adding the array object makes no sense to me. You probably meant to declaresumbefore the loop, and usesum += array[i];. Also, the singular of "entries" is "entry".iin any of your loops. This only works in non-strict, and is not a good habit to pick up.