Number of triangles after N moves | function to calculate number of triangles in Nth step ; Driver code
function numberOfTriangles ( n ) { var ans = 2 * ( Math . pow ( 3 , n ) ) - 1 ; return ans ; } var n = 2 ; document . write ( numberOfTriangles ( n ) ) ;