-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
216 lines (193 loc) · 7.67 KB
/
script.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
function handleFormSubmit(event) {
event.preventDefault();
}
let electIP, lpgIP, caolIP, airIP, railIP, metroIP, busIP, carIP, petrolIP, dieselIP, cngIP, mealIP, totalEmission, totalEmi;
function calculator() {
console.log("Submit Clicked!!");
electIP = document.getElementById("elect").value;
lpgIP = document.getElementById("lpg").value;
caolIP = document.getElementById("coal").value;
airIP = document.getElementById("air").value;
railIP = document.getElementById("rail").value;
metroIP = document.getElementById("metro").value;
busIP = document.getElementById("bus").value;
carIP = document.getElementById("car").value;
petrolIP = document.getElementById("petrol").value;
dieselIP = document.getElementById("diesel").value;
cngIP = document.getElementById("cng").value;
mealIP = document.querySelector('input[name="food"]:checked');
console.log("Selected Food:", mealIP.value);
if (mealIP == veg) {
totalEmission = (electIP * 0.00071) + (lpgIP * 0.00207) + (caolIP * 0.0025) + (airIP * 0.000121) + (railIP * 0.0078 / 1000) + (metroIP * 0.0139 / 1000) + (busIP * 0.054 / 1000) + (carIP * 0.1431 / 1000) + (2.176) + (petrolIP * 2.34 / 1000) + (dieselIP * 2.71 / 1000) + (cngIP * 2.07 / 1000);
} else if (mealIP == vegan) {
totalEmission = (electIP * 0.00071) + (lpgIP * 0.00207) + (caolIP * 0.0025) + (airIP * 0.000121) + (railIP * 0.0078 / 1000) + (metroIP * 0.0139 / 1000) + (busIP * 0.054 / 1000) + (carIP * 0.1431 / 1000) + (2.019) + (petrolIP * 2.34 / 1000) + (dieselIP * 2.71 / 1000) + (cngIP * 2.07 / 1000);
} else {
totalEmission = (electIP * 0.00071) + (lpgIP * 0.00207) + (caolIP * 0.0025) + (airIP * 0.000121) + (railIP * 0.0078 / 1000) + (metroIP * 0.0139 / 1000) + (busIP * 0.054 / 1000) + (carIP * 0.1431 / 1000) + (3.017) + (petrolIP * 2.34 / 1000) + (dieselIP * 2.71 / 1000) + (cngIP * 2.07 / 1000);
}
totalEmi = totalEmission.toFixed(2);
let target1 = document.getElementsByClassName("opBox1")[0];
let target2 = document.getElementsByClassName("opBox1")[1];
target1.innerHTML = "Your approximate Carbon Footprint";
target2.innerHTML = +totalEmi + " tonnes";
const electdt = electIP * 0.00071 * 1000000;
var fuelfooddt = (lpgIP * 0.00207) + (caolIP * 0.0025) * 1000000;
const airdt = (airIP * 0.000121) * 1000000;
var raildt = (railIP * 0.0078 / 1000) * 1000000;
var metrodt = (metroIP * 0.0139 / 1000) * 1000000;
var busdt = (busIP * 0.054 / 1000) * 1000000;
var publicdt = raildt + metrodt + busdt + airdt;
var cardt = (carIP * 0.1431 / 1000) * 1000000;
var petroldt = (petrolIP * 2.34 / 1000) * 1000000;
var dieseldt = (dieselIP * 2.71 / 1000) * 1000000;
var cngdt = (cngIP * 2.07 / 1000) * 1000000;
var fueldt = fuelfooddt + petroldt + dieseldt + cngdt;
// Data for labels and items
let labels = ['elect', 'fuel', 'public transport', 'car', 'fuel'];
let itemdata = [electdt, fueldt, publicdt, cardt, fueldt]; // Convert data to numbers
// Chart data configuration
const data = {
labels: labels,
datasets: [{
label: 'Items Data',
data: itemdata,
backgroundColor: 'rgb(191, 45, 45)',
}]
};
// Chart configuration
const config = {
type: 'line',
data: data,
};
// Create a new chart instance
const chart = new Chart(
document.getElementById('myChart1'),
config
);
// Data for labels and items
let labels2 = ['elect', 'fuel', 'public transport', 'car', 'fuel'];
let itemdata2 = [electdt, fueldt, publicdt, cardt, fueldt];// Convert data to numbers
// Chart data configuration
const data2 = {
labels: labels2,
datasets: [{
label: 'Items Data',
data: itemdata2,
backgroundColor: ['rgb(191, 45, 45)', 'rgb(191, 0, 45)', 'rgb(191, 45, 0)', 'rgb(191, 45, 45)', 'rgb(191, 0, 45)', 'rgb(191, 45, 0)', 'rgb(191, 45, 0)'],
}]
};
// Chart configuration
const config2 = {
type: 'pie',
data: data2,
};
// Create a new chart instance
const chart2 = new Chart(
document.getElementById('myChart2'),
config2
);
// Data for labels and items
let labels1 = ['yours', 'national average', 'global average'];
let itemdata1 = [totalEmission, 1.89, 4.66]; // Convert data to numbers
// Chart data configuration
const data1 = {
labels: labels1,
datasets: [{
label: 'Items Data',
data: itemdata1,
backgroundColor: 'rgb(191, 45, 45)',
}]
};
// Chart configuration
const config1 = {
type: 'bar',
data: data1,
options: {
indexAxis: 'y',
// Elements options apply to all of the options unless overridden in a dataset
// In this case, we are setting the border of each horizontal bar to be 2px wide
elements: {
bar: {
borderWidth: 0,
}
},
responsive: true,
}
};
// Create a new chart instance
const chart1 = new Chart(
document.getElementById('myChart3'),
config1
);
}
// Get elements
let n0 = document.querySelector(".n0");
let p1 = document.querySelector(".p1");
let n1 = document.querySelector(".n1");
let p2 = document.querySelector(".p2");
let n2 = document.querySelector(".n2");
let p10 = document.querySelector(".p10");
let n10 = document.querySelector(".n10");
let p3 = document.querySelector(".p3");
let n3 = document.querySelector(".n3");
let p4 = document.querySelector(".p4");
let n4 = document.querySelector(".n4");
let p5 = document.querySelector(".p5");
let n5 = document.querySelector(".n5");
let x = document.querySelector(".x");
let homeNav = document.querySelector(".homeNav");
let electricity = document.querySelector(".electricity");
let houseFuel = document.querySelector(".houseFuel");
let fasttravel = document.querySelector(".fasttravel");
let slowtravel = document.querySelector(".slowtravel");
let travelFuel = document.querySelector(".travelFuel");
let meal = document.querySelector(".meal");
let opBox = document.querySelector(".opBox");
let ipBox = document.querySelector(".ipBox");
// NEXT BUTTONS
n1.addEventListener('click', function(event) {
x.style.display = "none"
electricity.style.display = "none";
houseFuel.style.display = "block";
});
n2.addEventListener('click', function(event) {
houseFuel.style.display = "none";
fasttravel.style.display = "block";
});
n10.addEventListener('click', function(event) {
fasttravel.style.display = "none";
slowtravel.style.display = "block";
});
n3.addEventListener('click', function(event) {
slowtravel.style.display = "none";
travelFuel.style.display = "block";
});
n4.addEventListener('click', function(event) {
travelFuel.style.display = "none";
meal.style.display = "block";
});
n5.addEventListener('click', function(event) {
ipBox.style.display = "none";
opBox.style.display = "block";
});
// PREVIOUS BUTTONS
p2.addEventListener('click', function(event) {
houseFuel.style.display = "none";
electricity.style.display = "block";
x.style.display = "block";
});
p10.addEventListener('click', function(event) {
fasttravel.style.display = "none";
houseFuel.style.display = "block";
});
p3.addEventListener('click', function(event) {
slowtravel.style.display = "none";
fasttravel.style.display = "block";
});
p4.addEventListener('click', function(event) {
travelFuel.style.display = "none";
slowtravel.style.display = "block";
});
p5.addEventListener('click', function(event) {
meal.style.display = "none";
travelFuel.style.display = "block";
});