-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.js
73 lines (63 loc) · 1.98 KB
/
calculator.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
var rate21 = 50;
var rateDuo = 75;
var rate23 = 45;
var rate24 = 45;
/*The rates for the sailplanes are ^ */
var insWSCAC = 60;
var insYouAC = 70;
var insGrnd = 60;
/*The rates for instruction, in format ins<Aircraft><Place> ex. ins<WSC aircraft><In aircraft> = insWSCAC */
var tow = 1.4/100;
/*The rate per foot of tow.*/
function hr2min(hourTime) {
return hourTime*60;
}
//Turns hours into minutes.
function min2hr(minTime) {
return minTime/60;
}
function divide(firstNum, secondNum){
return firstNum/secondNum;
}
document.addEventListener("DOMContentLoaded", function() {
document.getElementById("calculButton").addEventListener("click", function(){calculatePrice();});
});
function calculatePrice() {
var airplanePrice;
var instPrice;
switch (document.getElementById("airplaneSel").value) {
case "ASK-21":
airplanePrice = rate21;
break;
case "DUO-X":
airplanePrice = rateDuo;
break;
case "ASK-23":
airplanePrice = rate23;
break;
case "ASW-24":
airplanePrice = rate24;
break;
default:
airplanePrice = 0;
break;
}
// airplanePrice ^
if (document.getElementById("instSel").value == "yes" && document.getElementById("airplaneSel").value == "Yours"){
instPrice = 70;
} else if (document.getElementById("airplaneSel").value == "ASK-23" || document.getElementById("airplaneSel").value == "ASW-24") {
instPrice = 0;
} else if (document.getElementById("instSel").value == "yes"){
instPrice = 60;
} else {
instPrice = 0;
}
// instPrice ^
var towPrice = (parseInt(document.getElementById("towHeight").value)*tow)/min2hr(parseInt(document.getElementById("eta").value));
// towPrice ^
var finalPrice = Math.round((airplanePrice+instPrice+towPrice)*100)/100;
//window.alert("$"+finalPrice+" per hour");
//alert($("#towHeight").value);
document.getElementById("resultMin").value = "$"+(Math.round((finalPrice/60)*100)/100);
document.getElementById("resultHour").value = "$"+finalPrice;
}