Considering all three - digit sequences
let threeDigit ; for ( let i = 0 ; i < ( len - 2 ) ; i ++ ) { threeDigit = ( n [ i ] - ' ' ) * 100 + ( n [ i + 1 ] - ' ' ) * 10 + ( n [ i + 2 ] - ' ' ) ; if ( threeDigit % 8 == 0 ) count ++ ; }