Affichage des articles dont le libellé est JavaScript Projects. Afficher tous les articles
Affichage des articles dont le libellé est JavaScript Projects. Afficher tous les articles

Banking Application Using HTML, CSS And Javascript

How To Create a Banking Application in JavaScript, HTML and CSS

How To Create a Banking Application in JavaScript, HTML and CSS


In this JavaScript Tutorial, we will see how to create a simple banking application using  JavaScript, HTML5, CSS3 and Chart.js .
We'll build a financial dashboard that includes real-time balance tracking, interactive transaction management, dynamic chart visualization, and a responsive user interface.
This banking project demonstrates essential web development concepts including DOM manipulation, event handling, data visualization with Chart.js, CSS Grid and Flexbox layouts.

What We Are Gonna Use In This Project:

- JavaScript Programming Language.
- HTML and CSS.
Chart.js .
- Visual Studio Editor.





Project Source Code:



     - Chart Initialization

Creates and configures the interactive balance chart using Chart.js.


// Create the chart for balance history
function initChart() {

const ctx = document.getElementById('balance-chart').getContext('2d');

chart = new Chart(ctx, {
type: 'line',
data: {
labels: [],
datasets: [{
label: 'Balance',
data: [],
borderColor: '#FF7600',
backgroundColor: 'rgba(255, 118, 0, 0.1)',
tension: 0.4,
fill: true
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
y: {
beginAtZero: true,
grid: {
color: 'rgba(255, 255, 255, 0.05)'
},
ticks: {
color: '#B0B0B0'
}
},
x: {
grid: {
display: false
},
ticks: {
color: '#B0B0B0',
maxRotation: 0,
maxTicksLimit: 5
}
}
},
plugins: {
legend: {
display: false
},
tooltip: {
mode: 'index',
intersect: false,
backgroundColor: 'rgba(30, 30, 30, 0.9)',
titleColor: '#FFFFFF',
bodyColor: '#FFFFFF',
borderColor: '#FF7600',
borderWidth: 1
}
}
}
});

}



     - Balance Display Updates.
    
A simple function that updates the balance display on the screen.


// Update the balance display
function updateBalance() {
// Show balance with 2 decimal places
balanceElement.textContent = `$${balance.toFixed(2)}`;
}



     - Transaction Recording.

This function handles the creation of new transactions.
 

// Add a new transaction to history
function addTransaction(type, amount) {
// Create a transaction object with type, amount and date
const transaction = {
type, // 'deposit' or 'withdraw'
amount,
date: new Date() // Current date and time
};

// Add to transactions list
transactions.push(transaction);

// Update the display
updateTransactionHistory();
updateChart();

// Reset scroll to top to show newest transactions
transactionHistory.scrollTop = 0;

}



     - Transaction History.

Display all the transactions (↑ for deposits, ↓ for withdrawals).


// Update the transaction history display
function updateTransactionHistory() {
// Clear the current list
transactionHistory.innerHTML = '';

// Loop through transactions in reverse order (newest first)
transactions.slice().reverse().forEach((transaction, index) => {
// Create a new transaction element
const transactionElement = document.createElement('div');
transactionElement.classList.add('transaction', transaction.type);

// Set icon based on transaction type
const iconContent = transaction.type === 'deposit' ? '↑' : '↓';

// Fill in the transaction details
transactionElement.innerHTML = `
<div class="transaction-icon">${iconContent}</div>
<div class="transaction-info">
<span class="transaction-type">${transaction.type}</span>
<span class="transaction-date">
                                        ${transaction.date.toLocaleString()}</span>
</div>
<span class="transaction-amount">
                                            $${transaction.amount.toFixed(2)}</span>
`;

// Add animation to make it fade in
transactionElement.style.animation =
                                        `fadeIn 0.3s ease-out ${index * 0.05}s both`;
transactionHistory.appendChild(transactionElement);

});
}



     - Chart Data Updates.

Keeps the balance chart synchronized with transaction data.


// Update the chart with new data
function updateChart() {
// Create labels (T1, T2, etc.) for each transaction
chart.data.labels = transactions.map((_, index) => `T${index + 1}`);

// Calculate running balance for each point
let runningBalance = 0;
chart.data.datasets[0].data = transactions.map(transaction => {
// Add amount for deposits, subtract for withdrawals
runningBalance += transaction.type === 'deposit' ?
                                            transaction.amount : -transaction.amount;
return runningBalance;
});

// Update the chart
chart.update();
}



     - Display error message.


// Show error popup
function showError(message) {
// Set the error message
errorMessage.textContent = message;
// Show the modal
errorModal.style.display = 'block';
errorModal.classList.add('show');
}



     - Dismiss The Error Message.


// Hide error popup
function hideError() {
// Start the hiding animation
errorModal.classList.remove('show');
// After animation finishes, hide the modal
setTimeout(() => {
errorModal.style.display = 'none';
}, 300);
}



     - Transaction Processing.


// Handle deposit or withdraw
function handleTransaction(type) {
// Get amount from input and convert to number
const amount = parseFloat(amountInput.value);

// Check if amount is valid
if (isNaN(amount) || amount <= 0) {
showError('Please enter a valid positive number');
return;
}

// Check if there's enough money for withdrawal
if (type === 'withdraw' && amount > balance) {
showError('Insufficient funds');
return;
}

// Update balance
balance += type === 'deposit' ? amount : -amount;

// Add to transaction history
addTransaction(type, amount);

// Update balance display
updateBalance();

// Clear input field
amountInput.value = '';
}



     - Button Click Handlers.


// Button click events
depositBtn.addEventListener('click', () => handleTransaction('deposit'));
withdrawBtn.addEventListener('click', () => handleTransaction('withdraw'));



     - Date Display.


// Show today's date in the header
currentDateElement.textContent = new Date().toLocaleDateString('en-US', {
year: 'numeric', month: 'long', day: 'numeric'
});





JavaScript - Create Conversion Tool with HTML, CSS, and JavaScript

How to Create a Simple Unit Conversion App with JavaScript 


How to Create a Simple Unit Conversion App with JavaScript



In this Javascript tutorial, we will see how to create a conversion tool to convert values between different units (e.g., inches to centimeters, pounds to kilograms, Fahrenheit to Celsius) and displays the converted result.



Project Source Code:



<!DOCTYPE html>
<html>
<head>
<title>conversion Tool</title>

<style>

body{ background-color: #f5f5f5; font-family: 'Open Sans', sans-serif; color: #333; }

#conversion-tool{ background-color: #fff; border-radius: 5px; padding: 20px; max-width: 400px;
margin: 20px auto; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1)
}

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

label{ font-weight: bold; margin-bottom: 5px; }

input[type="number"]:focus, select:focus{ outline: none; }

input[type="number"], select{
border: 1px solid #ddd; border-radius: 3px; padding: 5px;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
margin-bottom: 10px; font-size: 16px; background-color: #f2f2f2;
}


/* add a drop icon to the select */
select {
appearance: none;
background-image: url("data:image/svg+xml,%3Csvg width='12' height='6' viewBox='0 0 12 6'
xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0l6 6 6-6H0z' fill='%23333'
fill-opacity='0.4' fill-rule='evenodd'/%3E%3C/svg%3E");
background-repeat: no-repeat;
background-position: right 10px center;
padding-right: 25px;
}

button{ background-color: #333; color: #fff; border:none; border-radius: 5px;
padding: 10px 20px; cursor: pointer; transition: all 0.2s ease-in-out;
}

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

#output{ font-weight: bold; font-size: 16px; margin-top: 25px; }

#output-value{ color: purple; }

</style>

</head>
<body>


<div id="conversion-tool">
<form>
<label for="input-value">Value to Convert:</label>
<input type="number" id="input-value" min="0">
<br>
<label for="from-unit">Convert From:</label>
<select id="from-unit">
<option value="inches">Inches</option>
<option value="centimeters">Centimeters</option>
<option value="pounds">Pounds</option>
<option value="kilograms">Kilograms</option>
<option value="fahrenheit">Fahrenheit</option>
<option value="celesius">Celesius</option>
</select>
<br>
<label for="to-unit">Convert To:</label>
<select id="to-unit">
<option value="inches">Inches</option>
<option value="centimeters">Centimeters</option>
<option value="pounds">Pounds</option>
<option value="kilograms">Kilograms</option>
<option value="fahrenheit">Fahrenheit</option>
<option value="celesius">Celesius</option>
</select>
<br>
<button type="button" id="convert-btn">Convert</button>
<p id="output">Converted Value:<span id="output-value"></span></p>
</form>
</div>

<script>

// This function gets called when the "Convert" button is clicked
function convert()
{
// Get the user's input value and selected units
const inputValue = document.getElementById("input-value").value;
const fromUnit = document.getElementById("from-unit").value;
const toUnit = document.getElementById("to-unit").value;

// Initialize the output value as the input value
let outputValue = inputValue;

// Check the selected units and perform the appropriate calculations
if(fromUnit === "inches" && toUnit === "centimeters"){
outputValue = inputValue * 2.54;
}
else if(fromUnit === "centimeters" && toUnit === "inches"){
outputValue = inputValue / 2.54;
}

else if(fromUnit === "pounds" && toUnit === "kilograms"){
outputValue = inputValue * 0.453592;
}

else if(fromUnit === "kilograms" && toUnit === "pounds"){
outputValue = inputValue / 0.453592;
}

else if(fromUnit === "fahrenheit" && toUnit === "celesius"){
outputValue = (inputValue-32) * (5/9);
}

else if(fromUnit === "celesius" && toUnit === "fahrenheit"){
outputValue = (inputValue * (9/5)) + 32;
}

// Update the output field with the converted value
document.getElementById("output-value").innerHTML = outputValue;
}

// Attach the "convert" function to the "Convert" button's click event
document.getElementById("convert-btn").addEventListener("click", convert);


</script>


</body>
</html>




Code Explanation:

this JavaScript code, allows users to convert values between different units and displays the converted result..

This JavaScript code performs the following actions:

1 - The code defines a JavaScript function called convert() that performs the unit conversion.

2 - It retrieves user input values (value to convert, source unit, and target unit) from the HTML form.

3 - The function then calculates the converted value based on the selected units.

4 - The result of the conversion is displayed on the webpage..



OUTPUT:

Create Conversion Tool with HTML, CSS, and JavaScript









JavaScript - Create Note Taking App

How to Create a Note-Taking Application with JavaScript and Local Storage


JavaScript - Create Note Taking App


In this Javascript tutorial, we will see how to use JavaScript to create a basic note-taking application that allows users to add and delete notes saving and loading notes from local storage.




Project Source Code:



<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<!-- fontawesome -->
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css"
integrity="sha512-+4zCK9k+qNFUR5X+cKL9EIR+
ZOhtIloNl9GIKS57V1MyNsYpYcUrUeQc9vNfzsWfV28IaLL3i96P9sdNyeRssA=="
crossorigin="anonymous" />
<style>
#app{
width: 80%;
margin: 0 auto;
font-family: Arial, sans-serif;
}

#new-note{
display: flex;
align-items: center;
}

#new-note i{
font-size: 24px;
margin-right: 10px;
cursor: pointer;
transition: all 0.3s ease-in-out;
}

#new-note i:hover{ color: #0095ff; }

#new-note input{
border: none;
border-bottom: 2px solid #ccc;
font-size: 18px;
padding: 10px;
width: 100%;
transition: all 0.3s ease-in-out;
}

#new-note input:focus{border-bottom: 2px solid #0095ff; outline: none;}

#notes{margin-top: 20px;}

#notes li{
list-style: none;
border-bottom: 1px solid #ccc;
padding: 10px;
display: flex;
align-items: center;
}

#notes li i{
margin-right: 10px;
cursor: pointer;
transition: all 0.3s ease-in-out;
}

#notes li i:hover{ color: #0095ff; }

#notes li p{ margin: 0; font-size: 18px;}
</style>

</head>
<body>

<div id="app">
<h1>Note Taking App</h1>
<div id="new-note">
<i class="fas fa-plus"></i>
<input type="text" placeholder="take a new note...">
</div>
<ul id="notes"></ul>
</div>

<script>

// Select the "new note" div, the input field, and the notes list
const newNote = document.querySelector("#new-note");
const noteInput = newNote.querySelector("input");
const notesList = document.querySelector("#notes");

// Check if there are any saved notes in the local storage
// If there are, render them on the page
const savedNotes = JSON.parse(localStorage.getItem("notes")) || [];

if(savedNotes.length > 0)
{
savedNotes.forEach(note => {
const newNoteItem = document.createElement("li");
newNoteItem.innerHTML = `<i class="fas fa-trash"></i><p>${note}</p>`;
notesList.appendChild(newNoteItem);
});
}

// Add an event listener to the "new note" div
newNote.addEventListener("click", addNewNote);

// When the user click on the div, create a new note and add it to the list
// Also, save all notes in the list to the local storage
function addNewNote(e){

e.preventDefault();
const newNoteText = noteInput.value;
if(newNoteText === ""){
return;
}

const newNoteItem = document.createElement("li");
newNoteItem.innerHTML = `<i class="fas fa-trash"></i><p>${newNoteText}</p>`;
notesList.appendChild(newNoteItem);
noteInput.value = "";

const notes = [...notesList.querySelectorAll("li p")].map(note => note.textContent);
localStorage.setItem("notes", JSON.stringify(notes));
}

// Add an event listener to the notes list
notesList.addEventListener("click", deleteNote);

// When the user clicks the delete button next to a note, remove the note from the list
// Also, save all notes in the list to the local storage
function deleteNote(e){
if(e.target.classList.contains("fa-trash")){
e.target.parentElement.remove();
notes = [...notesList.querySelectorAll("li p")].map(note => note.textContent);
localStorage.setItem("notes", JSON.stringify(notes));
}
}




</script>


</body>
</html>





OUTPUT:

Create Note Taking App In JavaScript





if you want the source code click on the download button below


Image







Javascript - Create a Digital Clock

How To Make a Digital Clock Using Javascript  


Create a Digital Clock in Javascript


In This Javascript Tutorial we will See How To build a digital clock using JavaScript. 
The clock updates automatically every second, providing an interactive and dynamic experience for the users. 
Feel free to customize the styling or integrate the clock into your own web projects. Remember to experiment with the code and explore additional features you can add to enhance the clock's functionality . 



Project Source Code:

    
<!DOCTYPE html>
<html>
<head>
<title>Digital Clock</title>

<style>
#clock{
display: block;
width: 40%;
margin: 10px auto;
padding: 10px;
background-color: #3c3c3c;
color: #fff;
font-size: 36px;
font-family: Arial, sans-serif;
text-align: center;
border-radius: 5px;
box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.5);
}

</style>


</head>
<body>

<div id="clock"></div>

<script>

function updateClock()
{
// get the current time
var currentTime = new Date();
// get the hours, minutes, and seconds from the
// current time
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
var seconds = currentTime.getSeconds();
// format the hours, minutes,
// and seconds to always display two digits
if(hours < 10) { hours = "0" + hours; }

if(minutes < 10) { minutes = "0" + minutes; }

if(seconds < 10) { seconds = "0" + seconds; }

// get the clock div
var clockDiv = document.getElementById("clock");

// update the clock div with the current time
clockDiv.innerHTML = hours + ":" + minutes + ":" + seconds;

}

// calls the updateClock() function every 1000 milliseconds
// (or 1 second)
setInterval(updateClock, 1000);

</script>

</body>
</html>





Code Explanation:

This JavaScript code consists of a function called updateClock(), which is responsible for fetching the current time, formatting it, and updating the clock display on the webpage. Let's break down the code to understand its functionality.

Fetching Current Time: The updateClock() function starts by creating a new Date object called currentTime, which holds the current date and time. 

Extracting Hours, Minutes, and Seconds: Next, the code extracts the hours, minutes, and seconds from the currentTime object using the getHours(), getMinutes(), and getSeconds() methods, respectively.

Formatting Time: To ensure that the hours, minutes, and seconds are always displayed with two digits, the code checks if any of them are less than 10. If so, a leading zero is added to the value using simple conditional statements. 

Updating the Clock Display: The code retrieves the clock element from the webpage using the getElementById() method and assigns it to the clockDiv variable. Then, it updates the innerHTML property of the clockDiv with the formatted time (hours, minutes, and seconds). 

Automatic Clock Update: To make the clock update every second, the code employs the setInterval() function. It calls the updateClock() function every 1000 milliseconds (1 second), ensuring that the displayed time is always accurate and up to date.




OUTPUT:



Digital Clock Using Javascript