Skip to content

Commit

Permalink
Merge pull request #245 from Saimanjari777/expense-tracker
Browse files Browse the repository at this point in the history
Expense Tracker
  • Loading branch information
Avdhesh-Varshney authored Jun 5, 2024
2 parents 10c4df2 + df55c6f commit 0cbc514
Show file tree
Hide file tree
Showing 7 changed files with 237 additions and 1 deletion.
58 changes: 58 additions & 0 deletions Vanilla-JS-Projects/Basic/Expense-Tracker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<h1 align='center'><b>💥 EXPENSE TRACKER 💥</b></h1>

<!-- -------------------------------------------------------------------------------------------------------------- -->

<h3 align='center'>Tech Stack Used 🎮</h3>
<!-- enlist all the technologies used to create this project from them (Remove comment using 'ctrl+z' or 'command+z') -->

<div align='center'>

![HTML5](https://img.shields.io/badge/html5-%23E34F26.svg?style=for-the-badge&logo=html5&logoColor=white)
![CSS3](https://img.shields.io/badge/css3-%231572B6.svg?style=for-the-badge&logo=css3&logoColor=white)
![JavaScript](https://img.shields.io/badge/javascript-%23323330.svg?style=for-the-badge&logo=javascript&logoColor=%23F7DF1E)
</div>


![Line](https://github.com/Avdhesh-Varshney/WebMasterLog/assets/114330097/4b78510f-a941-45f8-a9d5-80ed0705e847)

<!-- -------------------------------------------------------------------------------------------------------------- -->

## :zap: Description 📃

- Beginner friendly project.
- The project is an expense tracker application built using HTML, CSS, and JavaScript.
- Designed with simplicity and functionality in mind, it allows users to add, delete expenses and show total amount spent.

<!-- -------------------------------------------------------------------------------------------------------------- -->

## :zap: How to run it? 🕹️

<!-- add the steps how to run the project -->
- Fork this project and run the `index.html` file directly.

<!-- -------------------------------------------------------------------------------------------------------------- -->

## :zap: Screenshots 📸
<!-- add the screenshot of the project (Mandatory) -->

![img](./screenshot.webp)


![Line](https://github.com/Avdhesh-Varshney/WebMasterLog/assets/114330097/4b78510f-a941-45f8-a9d5-80ed0705e847)


<!-- -------------------------------------------------------------------------------------------------------------- -->

<h4 align='center'>Developed By <b><i>Sai Manjari</i></b> 👧</h4>
<p align='center'>
<a href='https://www.linkedin.com/in/saimanjari777/'>
<img src='https://img.shields.io/badge/linkedin-%230077B5.svg?style=for-the-badge&logo=linkedin&logoColor=white' />
</a>
<a href='https://github.com/Saimanjari777'>
<img src='https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white' />
</a>
</p>

<h4 align='center'>Happy Coding 🧑‍💻</h4>

<h3 align="center">Show some &nbsp;❤️&nbsp; by &nbsp;🌟&nbsp; this repository!</h3>
44 changes: 44 additions & 0 deletions Vanilla-JS-Projects/Basic/Expense-Tracker/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html>
<head>
<title>Expense Tracker</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div class="container">
<h1>Expense Tracker</h1>
<form id="expense-form">
<input
type="text"
id="expense-name"
placeholder="Expense Name"
required
/>
<input
type="number"
id="expense-amount"
placeholder="Amount"
required
/>
<button type="submit">Add Expense</button>
</form>
<div class="expense-table">
<table>
<thead>
<tr>
<th>Expense Name</th>
<th>Amount</th>
<th>Action</th>
</tr>
</thead>
<tbody id="expense-list"></tbody>
</table>
<div class="total-amount">
<strong>Total:</strong>
$<span id="total-amount">0</span>
</div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
Binary file not shown.
50 changes: 50 additions & 0 deletions Vanilla-JS-Projects/Basic/Expense-Tracker/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const expenseForm = document.getElementById("expense-form");
const expenseList = document.getElementById("expense-list");
const totalAmountElement = document.getElementById("total-amount");
let expenses = JSON.parse(localStorage.getItem("expenses")) || [];
function renderExpenses() {
expenseList.innerHTML = "";
let totalAmount = 0;
for (let i = 0; i < expenses.length; i++) {
const expense = expenses[i];
const expenseRow = document.createElement("tr");
expenseRow.innerHTML = `
<td>${expense.name}</td>
<td>$${expense.amount}</td>
<td class="delete-btn" data-id="${i}">Delete</td>
`;
expenseList.appendChild(expenseRow);
totalAmount += expense.amount;
}
totalAmountElement.textContent = totalAmount.toFixed(2);
localStorage.setItem("expenses", JSON.stringify(expenses));
}
function addExpense(event) {
event.preventDefault();
const expenseNameInput = document.getElementById("expense-name");
const expenseAmountInput = document.getElementById("expense-amount");
const expenseName = expenseNameInput.value;
const expenseAmount = parseFloat(expenseAmountInput.value);
expenseNameInput.value = "";
expenseAmountInput.value = "";
if (expenseName === "" || isNaN(expenseAmount)) {
alert("Please enter valid expense details.");
return;
}
const expense = {
name: expenseName,
amount: expenseAmount,
};
expenses.push(expense);
renderExpenses();
}
function deleteExpense(event) {
if (event.target.classList.contains("delete-btn")) {
const expenseIndex = parseInt(event.target.getAttribute("data-id"));
expenses.splice(expenseIndex, 1);
renderExpenses();
}
}
expenseForm.addEventListener("submit", addExpense);
expenseList.addEventListener("click", deleteExpense);
renderExpenses();
78 changes: 78 additions & 0 deletions Vanilla-JS-Projects/Basic/Expense-Tracker/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
body {
font-family: Arial, sans-serif;
margin: 20px;
background-image: url(https://www.pixelstalk.net/wp-content/uploads/2016/06/Free-Download-Solid-Color-HD-Wallpapers.jpg);
background-repeat: no-repeat;
background-size: cover;
image-resolution: 2000px;
}
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0px 30px rgba(227, 228, 237, 0.3);
backdrop-filter: blur(30px);
border: 2px solid rgba(255, 255, 255, 0.18);
}
h1 {
text-align: center;
margin-bottom: 20px;
}
form {
display: flex;
justify-content: center;
margin-bottom: 20px;
}
input[type="text"],
input[type="number"] {
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
outline: none;
width: 250px;
margin-right: 10px;
}
input[type="text"]::placeholder,
input[type="number"]::placeholder {
color: #999;
}
button {
padding: 10px 20px;
background-color: #4caf50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
.expense-table {
border: 1px solid #ddd;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
table {
width: 100%;
border-collapse: collapse;
}
thead th {
background-color: #f2f2f2;
padding: 10px;
text-align: left;
}
tbody td {
padding: 10px;
border-top: 1px solid #ddd;
}
.delete-btn {
color: red;
cursor: pointer;
}
.total-amount {
padding: 10px;
text-align: right;
background-color: #f2f2f2;
}
3 changes: 2 additions & 1 deletion Vanilla-JS-Projects/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
| 26 | [Email-Subscription-form-with-google-sheet](./Intermediate/Email-Subscription-form-with-google-sheet/) | ![Intermediate](https://img.shields.io/badge/Intermediate-FFD700?style=for-the-badge) |
| 27 | [Dictonary-App](./Basic/Dictonary-App/) | ![Basic](https://img.shields.io/badge/Basic-00FF00?style=for-the-badge) |
| 28 | [Typing-Test](./Advanced/Typing-Test/) | ![Advanced](https://img.shields.io/badge/Advanced-FF0000?style=for-the-badge) |
| 29 | [RGB-Color-Slider](./Basic/RGB-Color-Slider/) | ![Basic](https://img.shields.io/badge/Basic-00FF00?style=for-the-badge) |
| 29 | [RGB-Color-Slider](./Basic/RGB-Color-Slider/) | ![Basic](https://img.shields.io/badge/Basic-00FF00?style=for-the-badge) |
| 29 | [Expense Tracker](./Basic/Expense-Tracker/) | ![Basic](https://img.shields.io/badge/Basic-00FF00?style=for-the-badge) |
</div>


Expand Down
5 changes: 5 additions & 0 deletions database/vanilla.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
"title": "Number To Words Convertor",
"description": "Number to Words convertor can facilitate users to convert any number into words instantly."
},
{
"tag": "Basic",
"title": "Expense Tracker",
"description": "This website helps you to add, delete and manage expenses. It gives the total amount spent."
},
{
"tag": "Basic",
"title": "Gallery",
Expand Down

0 comments on commit 0cbc514

Please sign in to comment.