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

Added Electric Vehicle Savings Calculator #1831

Merged
merged 2 commits into from
Aug 10, 2024
Merged
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
37 changes: 37 additions & 0 deletions Calculators/Electric-Vehicle-Savings-Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Electric Vehicle Savings Calculator</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>EV Savings Calculator</h1>
<form id="calculator-form">
<label for="petrol-avg">Petrol Vehicle Efficiency (kms/l):</label>
<input type="number" id="petrol-avg" step="0.1" placeholder="e.g. 12">

<label for="battery-cap">EV Battery Capacity (kWh):</label>
<input type="number" id="battery-cap" step="0.1" placeholder="e.g. 50">

<label for="ev-range">EV Range (kms):</label>
<input type="number" id="ev-range" step="1" placeholder="e.g. 300">

<label for="elec-cost">Cost of Electricity per kWh:</label>
<input type="number" id="elec-cost" step="0.01" placeholder="e.g. 0.20">

<button type="button" onclick="calculateCosts()">Calculate</button>
</form>

<div class="result">
<h3>Results</h3>
<p id="petrol-cost">Petrol Vehicle Cost per km: </p>
<p id="ev-cost">Electric Vehicle Cost per km: </p>
</div>
</div>

<script src="script.js"></script>
</body>
</html>
27 changes: 27 additions & 0 deletions Calculators/Electric-Vehicle-Savings-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function calculateCosts() {
const petrolAvg = parseFloat(document.getElementById("petrol-avg").value);
const batteryCap = parseFloat(document.getElementById("battery-cap").value);
const evRange = parseFloat(document.getElementById("ev-range").value);
const elecCost = parseFloat(document.getElementById("elec-cost").value);

if (
isNaN(petrolAvg) ||
isNaN(batteryCap) ||
isNaN(evRange) ||
isNaN(elecCost)
) {
alert("Please enter valid numbers for all fields.");
return;
}

// Petrol cost per km considering average petrol price in India
const petrolCostPerKm = ((1 / petrolAvg) * 100).toFixed(2); // Assuming an average fuel price of ₹100 per liter
const evCostPerKm = ((elecCost * batteryCap) / evRange).toFixed(2);

document.getElementById(
"petrol-cost"
).innerText = `Petrol Vehicle Cost per km: ₹${petrolCostPerKm}`;
document.getElementById(
"ev-cost"
).innerText = `Electric Vehicle Cost per km: ₹${evCostPerKm}`;
}
83 changes: 83 additions & 0 deletions Calculators/Electric-Vehicle-Savings-Calculator/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
body {
font-family: 'Arial', sans-serif;
background-color: #a6a6f0; /* Light background color for contrast */
color: #333; /* Darker text color for better readability */
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}

.container {
background-color: #ffffff; /* White background for the container */
padding: 40px;
border-radius: 12px; /* Rounded corners */
width: 400px; /* Slightly wider container */
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2); /* Enhanced shadow for depth */
border: 1px solid #e0e0e0; /* Light border for better separation */
}

h1 {
font-size: 1.8em;
margin-bottom: 20px; /* Added space below heading */
text-align: center;
color: #007bff; /* Bright blue for heading */
}

form {
display: flex;
flex-direction: column;
}

label {
margin-bottom: 5px; /* Spacing between label and input */
font-weight: 600; /* Slightly bolder font weight */
color: #555; /* Darker color for labels */
}

input, button {
width: 100%; /* Full width for inputs and button */
padding: 14px;
margin-bottom: 15px; /* Space between elements */
border: 1px solid #ccc; /* Light gray border */
border-radius: 6px; /* Rounded corners */
background-color: #f9f9f9; /* Lighter background for inputs and button */
color: #333; /* Darker text color for readability */
font-size: 1em; /* Consistent font size */
}

input:focus, button:focus {
outline: none;
border-color: #007bff; /* Highlight border color on focus */
box-shadow: 0 0 8px rgba(0, 123, 255, 0.5); /* Enhanced shadow on focus */
}

button {
background-color: #5959f8;
border: none;
color: #ffffff; /* White text color for button */
cursor: pointer;
font-weight: bold;
}

button:hover {
background-color: #014ea0;
}

.result {
margin-top: 20px; /* Space above results */
padding-top: 15px;
border-top: 1px solid #e0e0e0; /* Light border for separation */
}

.result h3 {
font-size: 1.3em;
margin-bottom: 10px;
color: #007bff; /* Bright blue for result heading */
}

.result p {
font-size: 1.1em;
margin: 5px 0; /* Space between result lines */
}
16 changes: 16 additions & 0 deletions Calculators/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# <p align="center">Electric Vehicle Savings Calculator</p>

## Description :-

Calculates savings from using an electric vehicle VS a gasoline vehicle.

## Tech Stacks :-

- HTML
- CSS
- JavaScript


## Screenshots :-
![WhatsApp Image 2024-08-09 at 00 04 40_1e3c53e0](https://github.com/user-attachments/assets/ce3a0c21-c163-426c-9b72-9f9a3584b46a)

14 changes: 14 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1836,6 +1836,20 @@ <h3>Calculates electricity costs based on user-supplied units, time, and cost pa
</a>
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Electric Vehicle Savings Calculator</h2>
<h3>Calculates savings from using an electric vehicle VS a gasoline vehicle.</h3>
<div class="card-footer">
<a href="./Calculators/Electric-Vehicle-Savings-Calculator/index.html" target="_blank">
<button>Try Now</button>
</a>
<a href="https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Electric-Vehicle-Savings-Calculator" title="Source Code" target="_blank">
<img src="./assets/images/github.png" alt="Source Code"></img>
</a>
</div>
</div>
</div>
<div class="box">
<div class="content">
Expand Down