heres the instruction:
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Finish the solution so that it returns the sum of all the multiples of 3 or 5 below the number passed in.
Note: If the number is a multiple of both 3 and 5, only count it once.
I got the output of 23 by adding all multiple of 3 and 5 but it saying, I'm wrong.
I'm new here plss help
function test() {
var a = [];
for (i=1; i<10; i++){
if ((i%3==0) || (i%5==0)){
a.push(i);
}
}
return a;
}
function sum(number){
var sum= 0;
for(i=0; i<number.length; i++){
sum += number[i];
}
return sum;
}
var ab = test();
var abc = sum(ab);
console.log(abc);
function test() {
var a = [];
for (i=1; i<10; i++){
if ((i%3==0) || (i%5==0)){
a.push(i);
}
}
return a;
}
function sum(number){
var sum= 0;
for(i=0; i<number.length; i++){
sum += number[i];
}
return sum;
}
var ab = test();
var abc = sum(ab);
console.log(abc);