Find the date after next half year from a given date | Function to find the date after the next half - year ; Stores the number of days in the months of a leap year ; List of months ; Days in half of a year ; Index of current month ; Starting day ; Decrement the value of cnt by 1 ; Increment cur_date ; If cnt is equal to 0 , then break out of the loop ; Update cur_month ; Update cur_date ; Print the resultant date ; Driver Code ; Function Call
function getDate ( d , m ) { let days = [ 31 , 29 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ] ; let month = [ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " ] ; let cnt = 183 ; let cur_month = 0 ; for ( let i = 0 ; i < 12 ; i ++ ) if ( m == month [ i ] ) cur_month = i ; let cur_date = d ; while ( true ) { while ( cnt > 0 && cur_date <= days [ cur_month ] ) { cnt -= 1 ; cur_date += 1 ; } if ( cnt == 0 ) break ; cur_month = ( cur_month + 1 ) % 12 ; cur_date = 1 ; } document . write ( cur_date + " " + month [ cur_month ] ) ; } let D = 15 ; let M = " " ; getDate ( D , M ) ;