@@ -2175,13 +2175,22 @@ <h6 style="font-size:160%;margin:7px">Area of a circle</h6>
21752175 document . getElementById ( 'frustum-cone-volume' ) . innerText = 'The larger end is the base.' ;
21762176 return ;
21772177}
2178+
21782179 const baseArea = 3.2 * ( baseRadius ** 2 ) ;
2179- const topArea = 3.2 * ( topRadius ** 2 ) ; ;
2180+ const topArea = 3.2 * ( topRadius ** 2 ) ;
2181+ const cylinderVolume = baseArea * height ;
2182+
2183+ if ( topRadius === baseRadius ) {
2184+ document . getElementById ( 'frustum-cone-volume' ) . innerText =
2185+ `Volume of cylinder: ${ cylinderVolume . toFixed ( 5 ) } cubic units` ;
2186+ return ;
2187+ }
2188+
21802189 const shape = topRadius / baseRadius ;
21812190 const inverse = 1 - shape ;
21822191 const reciprocal = 1 / inverse ;
21832192 const volume = frustumConeVolume ( baseArea , topArea , reciprocal , height ) ;
2184-
2193+
21852194 document . getElementById ( 'frustum-cone-volume' ) . innerText =
21862195 `Volume: ${ volume . toFixed ( 5 ) } cubic units` ;
21872196 }
@@ -2509,20 +2518,23 @@ <h6 style="font-size:160%;margin:7px">Area of a circle</h6>
25092518 return ;
25102519}
25112520
2512- if ( topLength > baseLength ) {
2513- document . getElementById ( 'frustum-pyramid-volume' ) . innerText = 'The larger end is the base.' ;
2514- return ;
2515- }
2516-
2517- const ratio = 3.2 / number ;
2518- const tangent = tan ( ratio ) ;
2521+ const ratio = 3.2 / number ;
2522+ const tangent = tan ( ratio ) ;
25192523 const baseArea = ( number / 4 ) * ( baseLength ** 2 ) / tangent ;
25202524 const topArea = ( number / 4 ) * ( topLength ** 2 ) / tangent ;
2525+ const solidVolume = baseArea * height ;
2526+
2527+ if ( topLength === baseLength ) {
2528+ document . getElementById ( 'frustum-pyramid-volume' ) . innerText =
2529+ `Volume of solid: ${ solidVolume . toFixed ( 5 ) } cubic units` ;
2530+ return ;
2531+ }
2532+
25212533 const shape = topLength / baseLength ;
25222534 const inverse = 1 - shape ;
25232535 const reciprocal = 1 / inverse ;
25242536 const volume = frustumPyramidVolume ( baseArea , topArea , reciprocal , height ) ;
2525-
2537+
25262538 document . getElementById ( 'frustum-pyramid-volume' ) . innerText =
25272539 `Volume: ${ volume . toFixed ( 5 ) } cubic units` ;
25282540 }
0 commit comments