Sum of integers upto N with given unit digit | Function to return the required sum ; If the unit digit is d ; Driver code
function getSum ( n , d ) { let sum = 0 ; for ( let i = 1 ; i <= n ; i ++ ) { if ( i % 10 == d ) sum += i ; } return sum ; } let n = 30 ; let d = 3 ; document . write ( getSum ( n , d ) ) ;