Skip to content

Commit 0fda3c1

Browse files
authored
Update index.html
1 parent b42ba9c commit 0fda3c1

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

index.html

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3055,7 +3055,7 @@ <h3 itemprop="eduQuestionType" style="margin:7px">Area of a Circle Segment</h3>
30553055
let l = parseFloat(lInput.value);
30563056
let r = parseFloat(rInput.value);
30573057

3058-
// If user edits the auto-filled field → reset
3058+
// Reset if user edits the auto-filled field
30593059
const activeElement = document.activeElement;
30603060
if (autoFilledField && activeElement.id === autoFilledField) {
30613061
hInput.value = "";
@@ -3066,10 +3066,18 @@ <h3 itemprop="eduQuestionType" style="margin:7px">Area of a Circle Segment</h3>
30663066
return;
30673067
}
30683068

3069+
// Count how many fields are filled
3070+
let filled = [!isNaN(h), !isNaN(l), !isNaN(r)].filter(Boolean).length;
3071+
3072+
if (filled < 2) {
3073+
output.innerText = "Enter one more value to compute.";
3074+
return;
3075+
}
3076+
30693077
// Derive missing field
30703078
if (!isNaN(h) && !isNaN(r) && isNaN(l)) {
3071-
let angle = Acos((r - h) / r);
3072-
l = 2 * r * sin(angle);
3079+
let angle = Math.acos((r - h) / r);
3080+
l = 2 * r * Math.sin(angle);
30733081
lInput.value = l.toFixed(5);
30743082
autoFilledField = "chord-length";
30753083
}
@@ -3086,17 +3094,12 @@ <h3 itemprop="eduQuestionType" style="margin:7px">Area of a Circle Segment</h3>
30863094

30873095
// Validity check
30883096
if (h > r || l < 2 * h || r < h) {
3089-
output.innerText = 'Invalid: must satisfy h ≤ r, l ≥ 2h, r ≥ h.';
3090-
// Clear auto-filled field to avoid stale values
3091-
if (autoFilledField) {
3092-
document.getElementById(autoFilledField).value = "";
3093-
autoFilledField = null;
3094-
}
3095-
return; // keep listening, but skip calculation
3097+
output.innerText = "Invalid: must satisfy h ≤ r, l ≥ 2h, r ≥ h.";
3098+
return; // keep listening, no lock
30963099
}
30973100

3098-
// Compute angle and area
3099-
let angle = Acos((r - h) / r);
3101+
// Compute area
3102+
let angle = Math.acos((r - h) / r);
31003103
let area = angle * r ** 2 - (r - h) * (l / 2);
31013104

31023105
// Output
@@ -3112,7 +3115,7 @@ <h3 itemprop="eduQuestionType" style="margin:7px">Area of a Circle Segment</h3>
31123115
document.getElementById('chord-length').addEventListener('input', segmentArea);
31133116
document.getElementById('parent-radius').addEventListener('input', segmentArea);
31143117
</script>
3115-
<p id="segment-area"></p>
3118+
<p id="segment-area"></p>
31163119
</div>
31173120
</section>
31183121
<br><br><br><br>

0 commit comments

Comments
 (0)