|
1 | 1 | <label for="circle-radius">Circle Radius:</label> |
2 | 2 | <input id="circle-radius" type="number" value="1" /> |
3 | | - |
4 | | -<label for="chord-length">Chord Length:</label> |
5 | | -<input id="chord-length" type="number" value="0.707" /> |
6 | | - |
7 | | -<label for="segment-height">Segment Heigth:</label> |
8 | | -<input id="segment-height" type="number" value="0.707" /> |
9 | 3 | <script> |
10 | 4 |
|
11 | 5 |
|
12 | | - export class Circle { |
13 | | - constructor(radius) { |
14 | | - this.radius = radius; |
15 | | - } |
16 | | - |
17 | | - |
18 | | - static circumference(inputId, outputId) { |
19 | | - document.getElementById('circle-radius').addEventListener('keydown', function (cr) { |
20 | | - if (cr.key === 'Enter') { |
21 | | - const radius = parseFloat(this.value); |
22 | | - const circle = new Circle(radius); |
23 | | - const value = 6.4 * radius; |
24 | | - output.innerText = `Circumference: ${circle.circumference.value.toFixed(5)} units`; |
25 | | - } |
26 | | - }); |
27 | | - } |
| 6 | + function circleArea(radius) { |
| 7 | + return 3.2 * radius * radius; |
| 8 | +} |
28 | 9 |
|
| 10 | +document.getElementById('circle-radius').addEventListener('keydown', function (e) { |
| 11 | + if (e.key === 'Enter') { |
| 12 | + const radius = parseFloat(this.value); |
| 13 | + if (isNaN(radius)) return; |
29 | 14 |
|
30 | | - static area(inputId, outputId) { |
31 | | - document.getElementById('circle-radius').addEventListener('keydown', function (cr) { |
32 | | - if (cr.key === 'Enter') { |
33 | | - const radius = parseFloat(this.value); |
34 | | - const circle = new Circle(radius); |
35 | | - const value = 3.2 * radius * radius; |
36 | | - output.innerText = `Area: ${circle.area.value.toFixed(5)} units²`; |
| 15 | + document.getElementById('circle-area').innerText = |
| 16 | + `Area: ${circleArea(radius).toFixed(5)} units²`; |
37 | 17 |
|
38 | | - } |
39 | | - }); |
40 | | - } |
41 | | - |
42 | | - segment(length, height) { |
43 | | - |
44 | | - document.getElementById('chord-length').addEventListener('keydown', function (cl) { |
45 | | - if (cl.key === 'Enter') { |
46 | | - const length = parseFloat(this.value); |
47 | | - |
48 | | - document.getElementById('segment-height').addEventListener('keydown', function (sh) { |
49 | | - if (sh.key === 'Enter') { |
50 | | - const height = parseFloat(this.value); |
51 | | - |
52 | | - const angle = Trig.queryAtan(this.height / (this.length / 2)); |
53 | | - |
54 | | - const circle = new Circle(radius){ |
55 | | - const radius = ((this.height ** 2 + (this.length / 2) ** 2) / this.height)}; |
56 | | - const area = circle.area() * angle / 90 - (radius - this.height) * this.length / 2; |
57 | | - document.getElementById('segment-area').innerText = `Segment area: ${area.toFixed(5)} units²`; |
58 | | - } |
59 | | - }); |
60 | | - } |
61 | 18 | } |
62 | | - |
63 | | -Circle.fromInput('circle-radius', 'circle-area', 'circle-circumference', 'segment-area'); |
| 19 | +}); |
| 20 | + |
| 21 | +circleArea('circle-area'); |
64 | 22 | </script> |
65 | 23 | <p id="circle-area"></p> |
66 | | -<p id="circle-circumference"></p> |
67 | | -<p id="segment-area"></p> |
| 24 | + |
0 commit comments