Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

PREVIOUS NEXT
Code Example
Javascript :: iterate through list js 
Javascript :: js fetch send json 
Javascript :: set multiple attributes javascript 
Javascript :: js one line if 
Javascript :: s3.getobject nodejs example async await 
Javascript :: javascript move last array element to first 
Javascript :: reactjs limit text display 20 200 characters 
Javascript :: vue add script tags and link tags 
Javascript :: string to int js 
Javascript :: clear textbox js 
Javascript :: infinite loop javascript 
Javascript :: clear arrays in jquery 
Javascript :: javascript string array sort alphabetically 
Javascript :: jquery data attribute 
Javascript :: convert array string to number 
Javascript :: sql json_extract 
Javascript :: javascript check if boolean is undefined 
Javascript :: padstart and padend javascript 
Javascript :: js is date 
Javascript :: check if a checkbox is checked jquery 
Javascript :: javascript round to 2 digits 
Javascript :: get random element from array js 
Javascript :: get youtube id from url javascript 
Javascript :: curl post json file 
Javascript :: replace url without reload js 
Javascript :: javascript get hour from date 
Javascript :: chart js x axis start at 0 
Javascript :: js send get method 
Javascript :: javascript template string examples 
Javascript :: google script wait 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =