-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbankAccount.js
More file actions
34 lines (31 loc) · 889 Bytes
/
bankAccount.js
File metadata and controls
34 lines (31 loc) · 889 Bytes
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
// BankAccount class
// - Properties
// - balance (defaults to 0 if not provided)
// - accountHolder
// - accountNumber
// - Methods
// - deposit(amt) - increases balance by amt
// - withdraw(amt) - descreases balance by amt.
class BankAccount {
constructor(accountNumber, accountHolder, balance = 0) {
this.accountHolder = accountHolder;
this.accountNumber = accountNumber;
this.balance = balance;
}
deposit(amt) {
if (amt > 0) {
this.balance += amt;
console.log(`You deposited $${amt}. New balance is: $${this.balance}`);
} else {
console.log("Can't deposit a negative amount");
}
}
withdraw(amt) {
if (amt > this.balance) {
console.log("You can't withdraw that much!");
} else {
this.balance -= amt;
console.log(`You withdrew $${amt}. New balance is: $${this.balance}`);
}
}
}