@@ -3043,31 +3043,32 @@ <h3 itemprop="eduQuestionType" style="margin:7px">Area of a Circle Segment</h3>
30433043< input id ="parent-radius " type ="number " step ="any " oninput ="segmentArea() ">
30443044< br >
30453045< script >
3046- function segmentArea ( ) {
3047- let h = parseFloat ( document . getElementById ( 'segment-height' ) . value ) ;
3048- let r = parseFloat ( document . getElementById ( 'parent-radius' ) . value ) ;
3049- let l = parseFloat ( document . getElementById ( 'chord-length' ) . value ) ;
3046+ function segmentArea ( ) {
3047+ let hVal = document . getElementById ( 'segment-height' ) . value ;
3048+ let rVal = document . getElementById ( 'parent-radius' ) . value ;
3049+ let lVal = document . getElementById ( 'chord-length' ) . value ;
3050+
3051+ // Treat empty string as NaN
3052+ let h = hVal === "" ? NaN : parseFloat ( hVal ) ;
3053+ let r = rVal === "" ? NaN : parseFloat ( rVal ) ;
3054+ let l = lVal === "" ? NaN : parseFloat ( lVal ) ;
30503055
30513056 let known = [ ! isNaN ( h ) , ! isNaN ( r ) , ! isNaN ( l ) ] . filter ( Boolean ) . length ;
30523057 if ( known < 2 ) {
3053- document . getElementById ( 'segment-area' ) . innerText = 'Enter one more property' ;
3054- return ;
3058+ document . getElementById ( 'segment-area' ) . innerText = "" ;
3059+ return ; // don’t auto‑fill anything
30553060 }
30563061
3057- // Case 1: height + radius known → derive length
3062+ // Derive missing property only once we have exactly 2 inputs
30583063 if ( ! isNaN ( h ) && ! isNaN ( r ) && isNaN ( l ) ) {
30593064 let angle = Acos ( ( r - h ) / r ) ;
30603065 l = 2 * r * sin ( angle ) ;
30613066 document . getElementById ( 'chord-length' ) . value = l . toFixed ( 5 ) ;
30623067 }
3063-
3064- // Case 2: height + length known → derive radius
30653068 if ( ! isNaN ( h ) && ! isNaN ( l ) && isNaN ( r ) ) {
30663069 r = ( l ** 2 + 4 * h ** 2 ) / ( 8 * h ) ;
30673070 document . getElementById ( 'parent-radius' ) . value = r . toFixed ( 5 ) ;
30683071 }
3069-
3070- // Case 3: length + radius known → derive height
30713072 if ( ! isNaN ( l ) && ! isNaN ( r ) && isNaN ( h ) ) {
30723073 h = r - Math . sqrt ( r ** 2 - ( l / 2 ) ** 2 ) ;
30733074 document . getElementById ( 'segment-height' ) . value = h . toFixed ( 5 ) ;
@@ -3076,30 +3077,24 @@ <h3 itemprop="eduQuestionType" style="margin:7px">Area of a Circle Segment</h3>
30763077 // Validity checks
30773078 if ( h > r || l < 2 * h || r < h ) {
30783079 document . getElementById ( 'segment-area' ) . innerText =
3079- 'The height of the segment must be shorter than the parent radius and half the length .' ;
3080+ 'Invalid input: must satisfy h ≤ r, l ≥ 2h, r ≥ h .' ;
30803081 return ;
30813082 }
30823083
30833084 // Compute angle and area
30843085 let angle = Acos ( ( r - h ) / r ) ;
30853086 let area = angle * r ** 2 - ( r - h ) * ( l / 2 ) ;
30863087
3087- // Output with semicircle reminders
3088- if ( h === r ) {
3089- document . getElementById ( 'segment-area' ) . innerText =
3090- `Semicircle area: ${ area . toFixed ( 5 ) } square units` ;
3091- } else if ( h === l / 2 ) {
3092- document . getElementById ( 'segment-area' ) . innerText =
3093- `Semicircle area: ${ area . toFixed ( 5 ) } square units` ;
3094- } else if ( l === 2 * r ) {
3088+ // Output
3089+ if ( h === r || h === l / 2 || l === 2 * r ) {
30953090 document . getElementById ( 'segment-area' ) . innerText =
30963091 `Semicircle area: ${ area . toFixed ( 5 ) } square units` ;
30973092 } else {
30983093 document . getElementById ( 'segment-area' ) . innerText =
30993094 `Area: ${ area . toFixed ( 5 ) } square units` ;
31003095 }
3101- }
3102- </ script >
3096+ }
3097+ </ script >
31033098 < p id ="segment-area "> </ p >
31043099</ div >
31053100</ section >
0 commit comments