Skip to content

Commit

Permalink
Merge pull request #35 from CrypticRevenger/main
Browse files Browse the repository at this point in the history
javascript project in top-notch #22 Add files via upload
  • Loading branch information
AkankshaAI authored Oct 6, 2023
2 parents 7d8cae0 + 5695f2f commit 00236c6
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 0 deletions.
Binary file not shown.
Binary file added JS projects/ExpenseTrackerApp/favicon.ico
Binary file not shown.
53 changes: 53 additions & 0 deletions JS projects/ExpenseTrackerApp/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<title>Expense Tracker App</title>
</head>
<body>
<h1>Expense Tracker App</h1>
<div class="input-section">
<label for="category-select" class="s1">Category:</label>
<select id="category-select">
<option value="Food & Beverage">Food & Beverage</option>
<option value="Rent">Rent</option>
<option value="Transport">Transport</option>
<option value="Relaxing">Relaxing</option>
</select>
<label for="amount-input">Amount:</label>
<input type="number" id="amount-input">
<label for="date-input">Date:</label>
<input type="date" id="date-input">
<button id="add-btn">Add</button>
</div>
<div class="expenses-list">
<h2>Expenses List</h2>
<table>
<thead>
<tr>
<th>Category</th>
<th>Amount</th>
<th>Date</th>
<th>Delete</th>
</tr>
</thead>
<tbody id="expnese-table-body">

</tbody>
<tfoot>
<tr>
<td>Total:</td>
<td id="total-amount"></td>
<td></td>
<td></td>
</tr>
</tfoot>
</table>
</div>
<script src="script.js"></script>
</body>
</html>
84 changes: 84 additions & 0 deletions JS projects/ExpenseTrackerApp/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
let expenses = [];
let totalAmount = 0;

const categorySelect = document.getElementById('category-select');
const amountInput = document.getElementById('amount-input');
const dateInput = document.getElementById('date-input');
const addBtn = document.getElementById('add-btn');
const expensesTableBody = document.getElementById('expnese-table-body');
const totalAmountCell = document.getElementById('total-amount');

addBtn.addEventListener('click', function() {
const category = categorySelect.value;
const amount = Number(amountInput.value);
const date = dateInput.value;

if (category === '') {
alert('Please select a category');
return;
}
if (isNaN(amount) || amount <=0 ) {
alert('Please enter a valid amount')
return;
}
if(date === '') {
alert('Please select a date')
return;
}
expenses.push({category, amount, date});

totalAmount += amount;
totalAmountCell.textContent = totalAmount;

const newRow = expensesTableBody.insertRow();

const categoryCell = newRow.insertCell();
const amountCell = newRow.insertCell();
const dateCell = newRow.insertCell();
const deleteCell = newRow.insertCell();
const deleteBtn = document.createElement('button');

deleteBtn.textContent = 'Delete';
deleteBtn.classList.add('delete-btn');
deleteBtn.addEventListener('click', function() {
expenses.splice(expenses.indexOf(expense), 1);

totalAmount -= expense.amount;
totalAmountCell.textContent = totalAmount;

expensesTableBody.removeChild(newRow);
});

const expense = expenses[expenses.length - 1];
categoryCell.textContent = expense.category;
amountCell.textContent = expense.amount;
dateCell.textContent = expense.date;
deleteCell.appendChild(deleteBtn);

});

for (const expense of expenses) {
totalAmount += expense.amount;
totalAmountCell.textContent = totalAmount;

const newRow = expensesTableBody.inserRow();
const categoryCell = newRow.insertCell();
const amountCell = newRow.insertCell();
const dateCell = newRow.insertCell();
const deleteCell = newRow.insertCell();
const deleteBtn = document.createElement('button');
deleteBtn.textContent = 'Delete';
deleteBtn.classList.add('delete-btn');
deleteBtn.addEventListener('click', function() {
expenses.splice(expenses.indexOf(expense), 1);

totalAmount -= expense.amount;
totalAmountCell.textContent = totalAmount;

expensesTableBody.removeChild(newRow);
});
categoryCell.textContent = expense.category;
amountCell.textContent = expense.amount;
dateCell.textContent = expense.date;
deleteCell.appendChild(deleteBtn);
}
110 changes: 110 additions & 0 deletions JS projects/ExpenseTrackerApp/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
body, h1, h2, p, ul, li, table, th, td {
margin: 0;
padding: 0;
list-style: none;
}

body {
font-family: Arial, sans-serif;
background-color: #caedf2;
margin: 0;
padding: 0;
}

/* Header Styles */
h1 {
background-color: #007BFF;
color: #fff;
text-align: center;
padding: 20px 0;
}

/* Input Section Styles */
.input-section {
background-color: #fff;
border-radius: 5px;
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
padding: 20px;
margin: 20px auto;
max-width: 600px;
text-align: center;
}

.input-section label {
display: block;
margin-bottom: 10px;
}

#category-select,
#amount-input,
#date-input,
#add-btn {
width: 100%;
padding: 10px;
margin-bottom: 20px;
border: 1px solid #ccc;
border-radius: 5px;
}

#category-select {
background-color: #f0f0f0;
}

#add-btn {
background-color: #007BFF;
color: #fff;
cursor: pointer;
transition: background-color 0.3s ease;
}

#add-btn:hover {
background-color: #0056b3;
}

/* Expenses List Styles */
.expenses-list {
background-color: #fff;
border-radius: 5px;
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
padding: 20px;
margin: 20px auto;
max-width: 600px;
}

.expenses-list h2 {
background-color: #007BFF;
color: #fff;
padding: 10px 0;
text-align: center;
margin-bottom: 20px;
}

table {
width: 100%;
border-collapse: collapse;
}

table th,
table td {
padding: 12px;
text-align: center;
border-bottom: 1px solid #ddd;
}

table th {
background-color: #007BFF;
color: #fff;
}

#total-amount {
font-weight: bold;
font-size: 1.2em;
}

/* Responsive Styles */
@media screen and (max-width: 768px) {
.input-section, .expenses-list {
width: 90%;
margin: 20px auto;
}
}

0 comments on commit 00236c6

Please sign in to comment.