Skip to content

Commit 2c06daf

Browse files
authored
Update index.html
1 parent 82fcf24 commit 2c06daf

1 file changed

Lines changed: 27 additions & 29 deletions

File tree

index.html

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3066,50 +3066,48 @@ <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-
3077-
// Derive missing field
3078-
if (!isNaN(h) && !isNaN(r) && isNaN(l)) {
3069+
// Workflow A: height + radius
3070+
if (!isNaN(h) && !isNaN(r)) {
30793071
let angle = Acos((r - h) / r);
30803072
l = 2 * r * sin(angle);
30813073
lInput.value = l.toFixed(5);
30823074
autoFilledField = "chord-length";
3075+
3076+
let area = angle * r ** 2 - (r - h) * (l / 2);
3077+
output.innerText = (h === r || h === l / 2 || l === 2 * r)
3078+
? `Semicircle area: ${area.toFixed(5)} square units`
3079+
: `Area: ${area.toFixed(5)} square units`;
3080+
return;
30833081
}
3084-
if (!isNaN(h) && !isNaN(l) && isNaN(r)) {
3082+
3083+
// Workflow B: height + length
3084+
if (!isNaN(h) && !isNaN(l)) {
30853085
r = (l ** 2 + 4 * h ** 2) / (8 * h);
30863086
rInput.value = r.toFixed(5);
30873087
autoFilledField = "parent-radius";
3088+
3089+
let angle = Acos((r - h) / r);
3090+
let area = angle * r ** 2 - (r - h) * (l / 2);
3091+
output.innerText = (h === r || h === l / 2 || l === 2 * r)
3092+
? `Semicircle area: ${area.toFixed(5)} square units`
3093+
: `Area: ${area.toFixed(5)} square units`;
3094+
return;
30883095
}
3089-
if (!isNaN(l) && !isNaN(r) && isNaN(h)) {
3096+
3097+
// Workflow C: length + radius
3098+
if (!isNaN(l) && !isNaN(r)) {
30903099
h = r - Math.sqrt(r ** 2 - (l / 2) ** 2);
30913100
hInput.value = h.toFixed(5);
30923101
autoFilledField = "segment-height";
3093-
}
30943102

3095-
// Validity check
3096-
if (h > r || l < 2 * h || r < h) {
3097-
output.innerText = "Invalid: must satisfy h ≤ r, l ≥ 2h, r ≥ h.";
3098-
return;
3103+
let angle = Acos((r - h) / r);
3104+
let area = angle * r ** 2 - (r - h) * (l / 2);
3105+
output.innerText = (h === r || h === l / 2 || l === 2 * r)
3106+
? `Semicircle area: ${area.toFixed(5)} square units`
3107+
: `Area: ${area.toFixed(5)} square units`;
3108+
return;
30993109
}
31003110

3101-
// Compute area
3102-
let angle = Acos((r - h) / r);
3103-
let area = angle * r ** 2 - (r - h) * (l / 2);
3104-
3105-
// Output
3106-
if (h === r || h === l / 2 || l === 2 * r) {
3107-
output.innerText = `Semicircle area: ${area.toFixed(5)} square units`;
3108-
return;
3109-
} else {
3110-
output.innerText = `Area: ${area.toFixed(5)} square units`;
3111-
}
3112-
}
31133111

31143112
// Attach listeners
31153113
document.getElementById('segment-height').addEventListener('input', segmentArea);

0 commit comments

Comments
 (0)