-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tranactions.js
51 lines (43 loc) · 1.42 KB
/
Tranactions.js
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
// Define the object structure for each transaction
const Transaction = {
payeeName: "",
amount: 0,
date: new Date(),
category: "", // Optional: You can add a category property for transactions
};
// Create an empty array to store transactions
const transactions = [];
// Add a sample transaction
transactions.push(Object.assign(Transaction, {
payeeName: "John Doe",
amount: 100,
category: "Shopping",
}));
// Function to add a new transaction
function addTransaction(payeeName, amount, category = "") {
const newTransaction = Object.assign({}, Transaction, {
payeeName,
amount,
category,
});
transactions.push(newTransaction);
}
// Function to display all transactions
function displayTransactions() {
if (transactions.length === 0) {
console.log("No transactions found.");
return;
}
console.log("PhonePe Transactions:");
for (const transaction of transactions)
{
console.log(
`Payee: ${transaction.payeeName}, Amount: ₹${transaction.amount}, Date: ${transaction.date.toLocaleDateString()}, Category: ${transaction.category || "Uncategorized"}`
);
}
}
// Add a few more transactions
addTransaction("Electric Bill", 250);
addTransaction("Movie Ticket", 150, "Entertainment");
// Display all transactions
displayTransactions();