"> ">

NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

<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">
<title>Banking-example</title>
<link rel="stylesheet" href="style.css">
</head>

<body>
<div class="container">
<h2>Bank - Check and withdraw money</h2>
<div class="data">
<label for="amount">Please enter the withdrawal money : </label>
<div id="accbal"></div>
</div>
<form>
<input type="number" id="amount" name="amount" step="0.01">
<button type="submit">Withdraw</button>
</form>
<div id="status-msg"></div>
</div>

<script src="script.js"></script>

</body>

</html>

html---

// Class implementing the BankAccount interface
var Bank = /** @class */ (function () {
// constructor to set the initial balance
function Bank(balance) {
this.balance = balance;
var accbal = document.querySelector("#accbal");
accbal.textContent = "Balance: ".concat(this.balance.toFixed(2));
accbal.style.color = "blue";
}
// method to withdraw money from the account
Bank.prototype.withdrawMoney = function (amount) {
var minBal = 500; // Minimum balance req. in the account
// check if the amount entered is valid
if (isNaN(amount) || amount <= 0) {
var message = "Please enter a valid amount";
var statusMsg = document.querySelector("#status-msg");
var form_1 = document.querySelector("form");
// display err. msg.
if (statusMsg && form_1) {
statusMsg.textContent = message;
statusMsg.style.color = "red";
}
}
// check if withdrawal amount exceed the max withdrawal amount
else if (this.balance - amount < minBal) {
var maxWithdrawal = this.balance - minBal; // max withdrawal
var statusMsg = document.querySelector("#status-msg");
var form_2 = document.querySelector("form");
// display warning msg.
if (form_2) {
statusMsg.textContent = "Withdawal unsuccessful, Max withdral amount is ".concat(maxWithdrawal.toFixed(2));
statusMsg.style.color = "orange";
}
}
// if the withdrawal is successful
else {
this.balance -= amount; // update the balance
var statusMsg = document.querySelector("#status-msg");
var accbal = document.querySelector("#accbal");
var form_3 = document.querySelector("form");
// display success msg.
if (statusMsg && form_3) {
statusMsg.textContent = "Withdawal successful, Remaining bal is ".concat(this.balance.toFixed(2));
statusMsg.style.color = "green";
accbal.textContent = "Balance: ".concat(this.balance.toFixed(2));
accbal.style.color = "blue";
}
}
};
return Bank;
}());
// Get HTML elements
var form = document.querySelector("form");
var amountInput = document.querySelector("#amount");
// create a new bank account instance
var myBank = new Bank(10000);
// add event listener for form submission
form === null || form === void 0 ? void 0 : form.addEventListener("submit", function (e) {
e.preventDefault();
var amount = parseFloat(amountInput.value);
myBank.withdrawMoney(amount);
});
script.js---

// Interface defining te properties and methods of a bank account
interface BankAccount {
balance: number; // property for curent balance
withdrawMoney: (amount: number) => void; // Methood to withdraw money
}
// Class implementing the BankAccount interface
class Bank implements BankAccount {
balance: number; // Property for current balance

// constructor to set the initial balance
constructor(balance: number) {
this.balance = balance;
var accbal = document.querySelector("#accbal") as HTMLDivElement;
accbal.textContent = `Balance: ${this.balance.toFixed(2)}`;
accbal.style.color = "blue";
}
// method to withdraw money from the account
withdrawMoney(amount: number): void {
const minBal = 500; // Minimum balance req. in the account

// check if the amount entered is valid
if (isNaN(amount) || amount <= 0) {
const message = "Please enter a valid amount";
const statusMsg = document.querySelector("#status-msg") as HTMLDivElement;
const form = document.querySelector("form");

// display err. msg.
if (statusMsg && form) {
statusMsg.textContent = message;
statusMsg.style.color = "red";
}
}
// check if withdrawal amount exceed the max withdrawal amount
else if (this.balance - amount < minBal) {
const maxWithdrawal = this.balance - minBal; // max withdrawal
const statusMsg = document.querySelector("#status-msg") as HTMLDivElement;
const form = document.querySelector("form");

// display warning msg.
if (form) {
statusMsg.textContent = `Withdawal unsuccessful, Max withdral amount is ${maxWithdrawal.toFixed(
2
)}`;
statusMsg.style.color = "orange";
}
}
// if the withdrawal is successful
else {
this.balance -= amount; // update the balance
const statusMsg = document.querySelector("#status-msg") as HTMLDivElement;
const accbal = document.querySelector("#accbal") as HTMLDivElement;
const form = document.querySelector("form");

// display success msg.
if (statusMsg && form) {
statusMsg.textContent = `Withdawal successful, Remaining bal is ${this.balance.toFixed(
2
)}`;
statusMsg.style.color = "green";
accbal.textContent = `Balance: ${this.balance.toFixed(2)}`;
accbal.style.color = "blue";
}
}
}
}
// Get HTML elements
var form = document.querySelector("form");
var amountInput = document.querySelector("#amount") as HTMLInputElement;
// create a new bank account instance
var myBank = new Bank(10000);
// add event listener for form submission
form?.addEventListener("submit", (e) => {
e.preventDefault();
const amount = parseFloat(amountInput.value);
myBank.withdrawMoney(amount);
});


script.ts----

* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
display: flex;
align-items: center;
text-align: center;
justify-content: center;
}
.container {
display: flex;
align-items: center;
text-align: center;
border: 1px solid black;
flex-direction: column;
padding: 20px;
border-radius: 5px;
background-color: rgb(247, 242, 236);
}
h2 {
margin-bottom: 20px;
}
.data,
form {
margin-bottom: 15px;
}
.data {
display: flex;
flex-direction: row;
gap: 10px;
}

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

input {
margin-right: 5px;
}

input,
button {
padding: 10px;
margin-bottom: 5px;
border-radius: 5px;
}

button {
color: #fff;
background-color: blue;
border: 1px solid blue;
font-size: 14px;
letter-spacing: 1.25px;
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}
csss-----
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.