forked from bethrobson/Head-First-JavaScript-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathareaAndDistance.html
More file actions
44 lines (39 loc) · 776 Bytes
/
areaAndDistance.html
File metadata and controls
44 lines (39 loc) · 776 Bytes
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Area and Distance</title>
</head>
<body>
</body>
<script>
var x = 32;
var y = 44;
var radius = 5;
var centerX = 0;
var centerY = 0;
var width = 600;
var height = 400;
function setup(width, height) {
centerX = width/2;
centerY = height/2;
}
function computeDistance(x1, y1, x2, y2) {
var dx = x1 - x2;
var dy = y1 - y2;
var d2 = (dx * dx) + (dy * dy);
var d = Math.sqrt(d2);
return d;
}
function circleArea(r) {
var area = Math.PI * r * r;
return area;
}
setup(width, height);
var area = circleArea(radius);
var distance = computeDistance(x, y, centerX, centerY);
alert("Area: " + area);
alert("Distance: " + distance);
</script>
</body>
</html>