Check if the door is open or closed | Function to check whether ' n ' has even number of factors or not ; if ' n ' is a perfect square it has odd number of factors ; else ' n ' has even number of factors ; Function to find and print status of each door ; If even number of factors final status is closed ; else odd number of factors final status is open ; Driver Code
function hasEvenNumberOfFactors ( n ) { let root_n = Math . sqrt ( n ) ; if ( ( root_n * root_n ) == n ) return false ; return true ; } function printStatusOfDoors ( n ) { for ( let i = 1 ; i <= n ; i ++ ) { if ( hasEvenNumberOfFactors ( i ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ; } } let n = 5 ; printStatusOfDoors ( n ) ;