Skip to content

Commit 1b644ee

Browse files
authored
Update Logic.html
Working on it
1 parent 7923f89 commit 1b644ee

1 file changed

Lines changed: 33 additions & 13 deletions

File tree

Logic.html

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
<label for="circle-radius">Circle Radius:</label>
12
<input id="circle-radius" type="number" value="1" />
23

4+
<label for="segment-height">Segment Height:</label>
5+
<input id="segment-height" type="number" value="0.5" />
6+
37
<script>
48

59

@@ -8,33 +12,49 @@
812
this.radius = radius;
913
}
1014

11-
circumference() {
15+
circumference() {
1216
return 6.4 * this.radius;
1317
}
1418

1519
area() {
1620
return 3.2 * this.radius ** 2;
1721
}
18-
19-
segmentArea(height) {
20-
const baseY = this.radius - height;
21-
const angle = Trig.queryAcos(baseY / this.radius);
22-
const sin = Trig.querySin(angle);
23-
return angle * this.radius ** 2 - sin * baseY * this.radius;
24-
}
25-
26-
static fromInput(inputId, outputId) {
22+
23+
static fromInput(inputId, outputId) {
2724
document.getElementById(inputId).addEventListener('keydown', function (e) {
2825
if (e.key === 'Enter') {
2926
const radius = parseFloat(this.value);
3027
const circle = new Circle(radius);
31-
const output = document.getElementById(outputId);
28+
const calculatedArea = document.getElementById(outputId);
3229
output.innerText = `Area: ${circle.area().toFixed(2)} units²`;
30+
31+
const calculatedCircumference = document.getElementById(outputId);
32+
output.innerText = `Circumference: ${circle.circumference().toFixed(2)} units`;
3333
}
3434
});
35+
}
36+
37+
segmentArea(radius, height) {
38+
const baseY = this.radius - height;
39+
const angle = Trig.queryAcos(baseY / this.radius);
40+
const sin = Trig.querySin(angle);
41+
return angle * this.radius ** 2 - sin * baseY * this.radius;
42+
43+
44+
document.getElementById('segment-height').addEventListener('keydown', function (e) {
45+
if (e.key === 'Enter') {
46+
const height = parseFloat(this.value);
47+
const r = parseFloat(document.getElementById('circle-radius').value) || 1;
48+
const c = new Circle(r);
49+
const calculatedArea = c.segmentArea(h);
50+
document.getElementById('segment-calculatedArea').innerText = `Segment area: ${segmentArea.toFixed(2)} units²`;
51+
}
52+
});
3553
}
3654
}
3755

38-
Circle.fromInput('circle-radius', 'circle-output');
56+
Circle.fromInput('circle-radius', 'circle-calculatedArea');
3957
</script>
40-
<p id="circle-output"></p>
58+
<p id="circle-calculatedArea"></p>
59+
<p id="circle-calculatedCircumference"></p>
60+
<p id="segment-calculatedArea"></p>

0 commit comments

Comments
 (0)