Project Euler Problems 1 to 100 - Problem 1: Multiples of 3 and 5

Tell us what’s happening:
returning zero('s the hero)

Your code so far

function multiplesOf3and5(number) {
 let sum = 0;
for(let i = 1; i > number; i++) {
 if(i % 3 === 0) {
   sum += i;
}
if(i % 5 === 0){
  sum += i;
}
}
  return sum;
}
console.log(multiplesOf3and5(49));

Your browser information:

User Agent is: Mozilla/5.0 (Android 13; Mobile; rv:109.0) Gecko/117.0 Firefox/117.0

Challenge: Project Euler Problems 1 to 100 - Problem 1: Multiples of 3 and 5

Link to the challenge:

This does not seem right.

i >= number;
also returns zero

You want to run this loop only when i is bigger than num?

guess i am not greater than a number after all v^<>

Pay attention to the if…else statement. You are missing ‘else’ {} in order to get the correct results. You have already got the direction for the direction of iteration through the for loop.

thanks yeah i changed it to a single if with"
||
in between so it worked " >

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.