I am trying to calculate the mean of the values in an array, but nothing comes out.
function medias() {
let notas = ['3', '6', '8', '2']
let media = 0;
for (let i = 0; i < notas; i++) {
media += notas[i];
}
console.log(media / notas.length);
}
medias();
How can I solve that?
There are several things to consider in your role.
The first thing is that your array must contain numerical data so that when added it does not concatenate them and gives you the result of the sum:
Without the quotes between the numbers.
Other details is in the cycle. You must take into account that you are counting up to the length of your array, so it is missing:
Notice that inside the loop we use the .length to condition the output.
Fixed that, it should now return the array by calling the method as mentioned in the comments.
In the end you would have: