I'm writing a code that lets you type in 10 random numbers into a prompt window. The numbers are stored in an array called tal
. I have figured out how to get the highest and the lowest value but I can't get the average. can someone help me with a solution or to get me on the right way?
Here's my code:
let tal = [];
for (i = 0; i < 10; i++) {
tal[i] = prompt('Add a number: ', '');
tal.sort(function(a, b) {
return a - b
});
}
document.body.innerHTML += Math.max.apply(null, tal) + '<br>';
document.body.innerHTML += Math.min.apply(null, tal) + '<br>';