Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript multiples of 3 and 5

function sumOfMultiples(number) {    
  let sum = 0;    for(let i=1; i<number; i++) {        
    if(i % 3 === 0 || i % 5 === 0){            
      sum += i;        
    }    
  }    
  return sum;
}

sumOfMultiples(10); // returns 23 as 3 + 5 + 6 + 9 = 23
sumOfMultiples(15); // returns 45 as 3 + 5 + 6 + 9 + 10 + 12 = 45
Source by medium.com #
 
PREVIOUS NEXT
Tagged: #javascript #multiples
ADD COMMENT
Topic
Name
4+9 =