Challenge: Command Pattern
In this challenge, you have to implement the command pattern to solve the given problem.
We'll cover the following...
We'll cover the following...
Problem statement
Study and run the code snippet below:
Press + to interact
Node.js
class BankAccount {constructor(amount){this.amount = amount}checkAmount() {console.log(this.amount)}withdrawMoney(withdrawamount) {if(withdrawamount > this.amount){console.log("Not enough money")}else{this.amount -= withdrawamount}}depositAmount(money){this.amount += money}}var account = new BankAccount(100)account.checkAmount()account.withdrawMoney(10)account.checkAmount()account.depositAmount(50)account.checkAmount()
In the code above, you have a BankAccount
class. You can check the amount
in the account using the checkAccount
function, withdraw a certain amount using the withdrawMoney
function, and deposit an amount using the depositAmount
function. ...