@@ -1184,26 +1184,24 @@ <h6 style="font-size:160%;margin:7px">Area of a circle</h6>
11841184
11851185< script >
11861186 function capVolume ( radius , height ) {
1187- return 1.6 * radius ** 2 * Math . sqrt ( 3.2 ) * height ;
1187+ return 1.6 * radius * radius * height * Math . sqrt ( 3.2 ) ;
11881188 }
11891189
1190- document . getElementById ( 'cap-radius' ) . addEventListener ( 'input' , function ( ) {
1191- const radius = parseFloat ( this . value ) ;
1192- if ( isNaN ( radius ) ) {
1193- document . getElementById ( 'cap-volume' ) . innerText = '' ;
1194- return ;
1195- }
1190+ function updateCapVolume ( ) {
1191+ const radius = parseFloat ( document . getElementById ( 'cap-radius' ) . value ) ;
1192+ const height = parseFloat ( document . getElementById ( 'cap-height' ) . value ) ;
11961193
1197- document . getElementById ( 'cap-height' ) . addEventListener ( 'input' , function ( ) {
1198- const height = parseFloat ( this . value ) ;
1199- if ( isNaN ( height ) ) {
1194+ if ( isNaN ( radius ) || isNaN ( height ) ) {
12001195 document . getElementById ( 'cap-volume' ) . innerText = '' ;
1201- return ;
1196+ return ;
12021197 }
1203-
1198+
12041199 document . getElementById ( 'cap-volume' ) . innerText =
1205- `Volume: ${ capVolume ( radius , height ) . toFixed ( 5 ) } units²` ;
1206- } ) ;
1200+ `Volume: ${ capVolume ( radius , height ) . toFixed ( 5 ) } units³` ;
1201+ }
1202+
1203+ document . getElementById ( 'cap-radius' ) . addEventListener ( 'input' , updateCapVolume ) ;
1204+ document . getElementById ( 'cap-height' ) . addEventListener ( 'input' , updateCapVolume ) ;
12071205</ script >
12081206< p style ="margin:12px; " id ="cap-volume "> </ p >
12091207</ div >
@@ -1250,35 +1248,33 @@ <h6 style="font-size:160%;margin:7px">Area of a circle</h6>
12501248< br >
12511249< div >
12521250< label style ="margin:12px; " for ="cone-radius "> Cone Radius:</ label >
1253- < input id ="cap -radius " type ="number " value ="1 " step ="any " />
1251+ < input id ="cone -radius " type ="number " value ="1 " step ="any " />
12541252< br >
12551253< label style ="margin:12px; " for ="cone-height "> Cone Height:</ label >
1256- < input id ="cap -height " type ="number " value ="1 " step ="any " />
1254+ < input id ="cone -height " type ="number " value ="1 " step ="any " />
12571255
12581256< script >
12591257 function coneVolume ( radius , height ) {
1260- return 3.2 * radius ** 2 * height / Math . sqrt ( 8 ) ;
1258+ return 3.2 * radius * radius * height / Math . sqrt ( 8 ) ;
12611259 }
12621260
1263- document . getElementById ( 'cone-radius' ) . addEventListener ( 'input' , function ( ) {
1264- const radius = parseFloat ( this . value ) ;
1265- if ( isNaN ( radius ) ) {
1266- document . getElementById ( 'cone-volume' ) . innerText = '' ;
1267- return ;
1268- }
1261+ function updateConeVolume ( ) {
1262+ const radius = parseFloat ( document . getElementById ( 'cone-radius' ) . value ) ;
1263+ const height = parseFloat ( document . getElementById ( 'cone-height' ) . value ) ;
12691264
1270- document . getElementById ( 'cone-height' ) . addEventListener ( 'input' , function ( ) {
1271- const height = parseFloat ( this . value ) ;
1272- if ( isNaN ( height ) ) {
1265+ if ( isNaN ( radius ) || isNaN ( height ) ) {
12731266 document . getElementById ( 'cone-volume' ) . innerText = '' ;
1274- return ;
1267+ return ;
12751268 }
1276-
1269+
12771270 document . getElementById ( 'cone-volume' ) . innerText =
1278- `Volume: ${ coneVolume ( radius , height ) . toFixed ( 5 ) } units²` ;
1279- } ) ;
1271+ `Volume: ${ coneVolume ( radius , height ) . toFixed ( 5 ) } units³` ;
1272+ }
1273+
1274+ document . getElementById ( 'cone-radius' ) . addEventListener ( 'input' , updateConeVolume ) ;
1275+ document . getElementById ( 'cone-height' ) . addEventListener ( 'input' , updateConeVolume ) ;
12801276</ script >
1281- < p style ="margin:12px; " id ="cap -volume "> </ p >
1277+ < p style ="margin:12px; " id ="cone -volume "> </ p >
12821278</ div >
12831279< br >
12841280< div class ="imgbox ">
0 commit comments