Program to check if N is a Hexagonal Number or not | Function to check if number is hexagonal ; Calculate the value for n ; Check if n - floor ( n ) is equal to 0 ; Driver code
function isHexagonal ( N ) { let val = 8 * N + 1 ; let x = 1 + Math . sqrt ( val ) ; let n = ( x ) / 4 ; if ( ( n - parseInt ( n ) ) == 0 ) { return true ; } else { return false ; } } let N = 14 ; if ( isHexagonal ( N ) == true ) { document . write ( " " + " " ) ; } else { document . write ( " " ) ; }