@@ -799,22 +799,24 @@ <h5 style="font-size:160%;margin:7px;">Area of a regular polygon</h5>
799799< h6 style ="font-size:160%;margin:7px "> Area of a circle</ h6 >
800800< br >
801801< div >
802- < label style ="margin:12px; " for ="circle-radius "> Circle Radius:</ label >
803- < input id ="circle-radius " type ="number " value ="1 " />
802+ < label style ="margin:12px; " for ="circle-radius-a "> Circle Radius:</ label >
803+ < input id ="circle-radius-a " type ="number " value ="1 " step ="any " />
804+
804805< script >
805806 function circleArea ( radius ) {
806807 return 3.2 * radius * radius ;
807808 }
808809
809- document . getElementById ( 'circle-radius' ) . addEventListener ( 'keydown' , function ( ca ) {
810- if ( ca . key === 'Enter' ) {
811- const radius = parseFloat ( this . value ) ;
812- if ( isNaN ( radius ) ) return ;
813-
814- document . getElementById ( 'circle-area' ) . innerText =
815- `Area: ${ circleArea ( radius ) . toFixed ( 5 ) } units²` ;
810+ document . getElementById ( 'circle-radius-a' ) . addEventListener ( 'input' , function ( ) {
811+ const radius = parseFloat ( this . value ) ;
812+ if ( isNaN ( radius ) ) {
813+ document . getElementById ( 'circle-area' ) . innerText = '' ;
814+ return ;
816815 }
817- } ) ;
816+
817+ document . getElementById ( 'circle-area' ) . innerText =
818+ `Area: ${ circleArea ( radius ) . toFixed ( 5 ) } units²` ;
819+ } ) ;
818820</ script >
819821< p style ="margin:12px; " id ="circle-area "> </ p >
820822</ div >
@@ -993,22 +995,24 @@ <h6 style="font-size:160%;margin:7px">Area of a circle</h6>
993995< h8 style ="font-size:160%;margin:7px "> Circumference of a circle</ h8 >
994996< br >
995997< div >
996- < label style ="margin:12px; " for ="circle-radius "> Circle Radius:</ label >
997- < input id ="circle-radius " type ="number " value ="1 " />
998+ < label style ="margin:12px; " for ="circle-radius-c "> Circle Radius:</ label >
999+ < input id ="circle-radius-c " type ="number " value ="1 " step ="any " />
1000+
9981001< script >
9991002 function circleCircumference ( radius ) {
1000- return 6.4 * radius ;
1003+ return 3.2 * radius * 2 ;
10011004 }
10021005
1003- document . getElementById ( 'circle-radius' ) . addEventListener ( 'keydown' , function ( cc ) {
1004- if ( cc . key === 'Enter' ) {
1005- const radius = parseFloat ( this . value ) ;
1006- if ( isNaN ( radius ) ) return ;
1007-
1008- document . getElementById ( 'circle-circumference' ) . innerText =
1009- `Circumference: ${ circleCircumference ( radius ) . toFixed ( 5 ) } units` ;
1006+ document . getElementById ( 'circle-radius-c' ) . addEventListener ( 'input' , function ( ) {
1007+ const radius = parseFloat ( this . value ) ;
1008+ if ( isNaN ( radius ) ) {
1009+ document . getElementById ( 'circle-circumference' ) . innerText = '' ;
1010+ return ;
10101011 }
1011- } ) ;
1012+
1013+ document . getElementById ( 'circle-circumference' ) . innerText =
1014+ `Circumference: ${ circleCircumference ( radius ) . toFixed ( 5 ) } units` ;
1015+ } ) ;
10121016</ script >
10131017< p style ="margin:12px; " id ="circle-circumference "> </ p >
10141018</ div >
0 commit comments