-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfare.html
More file actions
56 lines (52 loc) · 1.71 KB
/
fare.html
File metadata and controls
56 lines (52 loc) · 1.71 KB
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
49
50
51
52
53
54
55
56
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<h1>fare calculator</h1>
<label for="start-destination">Entry KM: </label>
<select id="start-destination">
<option value="Station 1">meycauayan</option>
<option value="Station 2">sta maria</option>
<option value="Station 3">bocaue</option>
</select>
<label for="end-destination">Exit KM:</label>
<select id="end-destination">
<option value="Station 1">meycauayan</option>
<option value="Station 2">sta maria</option>
<option value="Station 3">bocaue</option>
</select>
<button id="calculate-fare" onclick="calculateFare()">submit</button>
<div id="fare-result">hey :</div>
<script>
function calculateFare() {
const fareMatrix = {
"Station 1": {
"Static 1": 0,
"Station 2": 2.0,
"Station 3": 4.0,
},
"Station 2": {
"Station 1": 2.0,
"Station 2": 0,
"Station 3": 2.0,
},
"Station 3": {
"Station 1": 4.0,
"Station 2": 2.0,
"Station 3": 0,
},
};
document.getElementById("calculate-fare").addEventListener("click", () => {
const startDestination = document.getElementById("start-destination").value;
const endDestination = document.getElementById("end-destination").value;
const fare = fareMatrix[startDestination][endDestination];
document.getElementById("fare-result").innerHTML = 'FARE: $${fare.toFixed(2)}';
});
}
</script>
</body>
</html>