Hi, I am trying to create a program that adds the multiples of 3 and 5 that are between 0 and 10. Well, I do not know what I'm doing wrong that the sum gives me 33, when it should be 23. Do you see the error in my code ...? Thanks.
function multiple(valor, multiple) {
resto = valor % multiple;
if (resto == 0)
return true;
else
return false;
}
// Arrays que contendran los valores multiples del 3 y del 5
let multiples_3 = [];
for (let i = 1; i <= 10; i++) {
if (multiple(i, 3))
multiples_3.push(i);
if (multiple(i, 5))
multiples_3.push(i);
}
let a = multiples_3
let suma = 0;
for (let i = 0; i < multiples_3.length; i++) {
suma += multiples_3[i]
}
alert(suma)