-
Notifications
You must be signed in to change notification settings - Fork 0
/
geometric.js
48 lines (43 loc) · 2.22 KB
/
geometric.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function calculateRectangle() {
var width = document.getElementById("rect-width").value;
var height = document.getElementById("rect-height").value;
var perimeter = 2 * (parseInt(width) + parseInt(height));
var area = parseInt(width) * parseInt(height);
var output = document.getElementById("rect-output");
output.innerHTML = "Perimeter: " + perimeter + "<br>Area: " + area;
}
function calculateCircle() {
var radius = document.getElementById("circle-radius").value;
var circumference = 2 * Math.PI * parseInt(radius);
var area = Math.PI * parseInt(radius) ** 2;
var output = document.getElementById("circle-output");
output.innerHTML = "Circumference: " + circumference + "<br>Area: " + area;
}
function calculateLine() {
var x1 = document.getElementById("line-x1").value;
var y1 = document.getElementById("line-y1").value;
var x2 = document.getElementById("line-x2").value;
var y2 = document.getElementById("line-y2").value;
var length = Math.sqrt((parseInt(x2) - parseInt(x1)) ** 2 + (parseInt(y2) - parseInt(y1)) ** 2);
var output = document.getElementById("line-output");
output.innerHTML = "Length: " + length;
}
function calculateDistance() {
var x1 = document.getElementById("dist-x1").value;
var y1 = document.getElementById("dist-y1").value;
var x2 = document.getElementById("dist-x2").value;
var y2 = document.getElementById("dist-y2").value;
var distance = Math.sqrt((parseInt(x2) - parseInt(x1)) ** 2 + (parseInt(y2) - parseInt(y1)) ** 2);
var output = document.getElementById("dist-output");
output.innerHTML = "Distance: " + distance;
}
function calculateTriangle() {
var side1 = document.getElementById("tri-side1").value;
var side2 = document.getElementById("tri-side2").value;
var side3 = document.getElementById("tri-side3").value;
var perimeter = parseInt(side1) + parseInt(side2) + parseInt(side3);
var s = perimeter / 2;
var area = Math.sqrt(s * (s - parseInt(side1)) * (s - parseInt(side2)) * (s - parseInt(side3)));
var output = document.getElementById("tri-output");
output.innerHTML = "Perimeter: " + perimeter + "<br>Area: " + area;
}