Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue - #1602 Solved - Added Eco-friendly Decision Maker #1603

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions projects/Eco-friendly Decision Maker/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
<title>Eco-Friendly Decision Maker</title>
</head>
<body>
<div class="container">
<h1>Eco-Friendly Decision Maker</h1>
<div id="form-container">
<label for="choice">Choose your activity:</label>
<select id="choice">
<option value="car">Driving a car</option>
<option value="bus">Taking a bus</option>
<option value="bike">Riding a bike</option>
<option value="walk">Walking</option>
<option value="shop">Shopping</option>
</select>
<button id="calculate-button">Calculate Carbon Footprint</button>
</div>
<div id="result-container" style="display: none;">
<p id="result"></p>
<p id="suggestion"></p>
<button id="restart-button">Try Another Activity</button>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
23 changes: 23 additions & 0 deletions projects/Eco-friendly Decision Maker/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const carbonFootprintData = {
car: { footprint: 250, suggestion: "Consider carpooling or using public transport." },
bus: { footprint: 100, suggestion: "Great choice! You can further reduce impact by walking to the station." },
bike: { footprint: 10, suggestion: "Awesome! Riding a bike is eco-friendly." },
walk: { footprint: 0, suggestion: "Excellent! Walking is the most eco-friendly option." },
shop: { footprint: 20, suggestion: "Consider buying local products or using eco-friendly materials." }
};

document.getElementById('calculate-button').addEventListener('click', () => {
const choice = document.getElementById('choice').value;
const result = carbonFootprintData[choice];

document.getElementById('result').textContent = `Your estimated carbon footprint: ${result.footprint} g CO2`;
document.getElementById('suggestion').textContent = result.suggestion;

document.getElementById('form-container').style.display = 'none';
document.getElementById('result-container').style.display = 'block';
});

document.getElementById('restart-button').addEventListener('click', () => {
document.getElementById('form-container').style.display = 'block';
document.getElementById('result-container').style.display = 'none';
});
44 changes: 44 additions & 0 deletions projects/Eco-friendly Decision Maker/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
background-color: #f0f8ff;
color: #333;
font-family: Arial, sans-serif;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}

.container {
text-align: center;
background-color: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
}

label {
margin-right: 10px;
}

select, button {
padding: 10px;
margin-top: 10px;
border-radius: 5px;
border: 1px solid #ccc;
}

button {
background-color: #28a745;
color: white;
cursor: pointer;
}

button:hover {
background-color: #218838;
}