I have a problem with the following exercise:
Enter N number of numbers by prompt. Show the average of the 1-digit numbers entered. End the program with the word “exit"/"salir”.
I also have to do the average calculation with a function. Here's what I have:
let i;
var sum = 0;
var avg = 0;
var average = function(i) {
sum = sum + i;
avg = sum/(i+1);
}
do {
i = prompt("Ingrese un numero: ");
if ((i < 10) && (i > -10)) {
average(i);
}
} while (i !== "salir");
alert(`el promedio de los numeros de un solo digito es: ${avg}`);
I tried limiting the program by stating that the average function will only be executed for one digit numbers, but the problem is that this is giving me the total average of all the numbers entered not the average of only the 1 digit numbers.