15 lines
488 B
JavaScript
15 lines
488 B
JavaScript
function calc() {
|
|
let resultado = 0;
|
|
const numeros = [];
|
|
const quantity = parseInt(prompt("Ingrese la cantidad de números a sumar."));
|
|
|
|
for (let i = 0; i < quantity; i++) {
|
|
numeros[i] = parseInt(prompt("Ingrese el "+(i+1)+"° número."));
|
|
while (isNaN(numeros[i]) == true) {
|
|
numeros[i] = parseInt(prompt("Repita el "+(i+1)+"° número."));
|
|
}
|
|
resultado += numeros[i];
|
|
}
|
|
|
|
alert("El resultado de la suma es "+resultado);
|
|
} |