forked from GarimaSingh0109/WasteManagment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
carbon-footprint.html
151 lines (130 loc) · 5.42 KB
/
carbon-footprint.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Carbon Footprint Calculator</title>
<link rel="stylesheet" href="Carbo-footprint.css">
</head>
<body>
<!-- Progress Bar -->
<div id="progress-container">
<div id="progress-bar"></div>
</div>
<!-- Navbar section -->
<header>
<a href="index.html"><h1>Waste Management</h1></a>
<nav>
<ul id="nav-menu">
<li><a href="#upload">Upload</a></li>
<li><a href="#features">Features</a></li>
<li><a href="#feedback">Feedback</a></li>
<li><a href="#about">About US</a></li>
<li><a href="register.html">Sign up</a></li>
<li><a href="#footer">Contact</a></li>
</ul>
</nav>
<div class="nav-controls">
<button id="theme-toggle" aria-label="Toggle dark mode">🌓</button>
<button id="menu-toggle" aria-label="Toggle menu">☰</button>
</div>
</header>
<main>
<div class="container">
<h1>Carbon Footprint Calculator</h1>
<form id="footprintForm">
<label for="wasteAmount">Waste Amount (kg per week):</label>
<input type="number" id="wasteAmount" required>
<label for="recycledAmount">Recycled Waste (kg per week):</label>
<input type="number" id="recycledAmount" required>
<button type="submit">Calculate</button>
</form>
<div id="result" class="result"></div>
<div id="tips" class="tips"></div>
</div>
</main>
<footer id="footer">
<h2>Stay Connected</h2>
<form id="newsletter-form">
<input type="email" placeholder="Your Email" required>
<button type="submit">Subscribe</button>
</form>
<div class="social-media">
<a href="#">
<box-icon type="logo" name="facebook"></box-icon>
</a>
<a href="#">
<box-icon type="logo" name="twitter"></box-icon>
</a>
<a href="#">
<box-icon type="logo" name="instagram"></box-icon>
</a>
</div>
<div class="community-message">
<h3>Our Commitment to Sustainability</h3>
<p>At Waste Management, we are dedicated to building a greener future. Through our community recycling programs and sustainability initiatives, we strive to reduce waste and protect the environment for generations to come. Join us in our mission to create a cleaner, healthier planet.</p>
</div>
<br>
<p>© 2024 Waste Management. All rights reserved.</p>
</footer>
<script>
document.addEventListener('DOMContentLoaded', (event) => {
const menuToggle = document.getElementById('menu-toggle');
const navMenu = document.getElementById('nav-menu');
const themeToggle = document.getElementById('theme-toggle');
const body = document.body;
// Menu toggle functionality
if (menuToggle && navMenu) {
menuToggle.addEventListener('click', () => {
navMenu.classList.toggle('show');
});
}
// Theme toggle functionality
if (themeToggle) {
themeToggle.addEventListener('click', () => {
body.classList.toggle('dark-mode');
themeToggle.textContent = body.classList.contains('dark-mode') ? '☀️' : '🌓';
});
}
});
document.getElementById('footprintForm').addEventListener('submit', function(event) {
event.preventDefault(); // Prevent the default form submission
// Get input values
const wasteAmount = parseFloat(document.getElementById('wasteAmount').value);
const recycledAmount = parseFloat(document.getElementById('recycledAmount').value);
// Validate inputs
if (isNaN(wasteAmount) || isNaN(recycledAmount)) {
alert("Please enter valid numbers.");
return;
}
// Calculate carbon footprint
const netWaste = wasteAmount - recycledAmount;
const carbonFootprint = netWaste * 0.5; // Example factor
// Display results
const resultDiv = document.getElementById('result');
resultDiv.innerHTML = `Your estimated carbon footprint is <strong>${carbonFootprint.toFixed(2)} kg CO2</strong> per week.`;
// Provide tips based on the result
let tips = '';
if (carbonFootprint < 10) {
tips = 'Great job! Keep reducing waste and recycling more.';
} else if (carbonFootprint >= 10 && carbonFootprint < 20) {
tips = 'You are doing well, but there’s room for improvement. Try to recycle more!';
} else {
tips = 'Consider reducing your waste and increasing your recycling efforts to lower your carbon footprint.';
}
const tipsDiv = document.getElementById('tips');
tipsDiv.innerHTML = `<strong>Tips:</strong> ${tips}`;
});
const progressBar = document.getElementById('progress-bar');
if (progressBar) {
window.addEventListener('scroll', () => {
const windowHeight = window.innerHeight;
const documentHeight = document.documentElement.scrollHeight;
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
const scrollPercentage = (scrollTop / (documentHeight - windowHeight)) * 100;
progressBar.style.width = scrollPercentage + '%';
});
}
</script>
</body>
</html>