Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cd4a0bf

Browse files
committed
old code deleted
1 parent 478ccca commit cd4a0bf

File tree

4 files changed

+0
-250
lines changed

4 files changed

+0
-250
lines changed

Week4/prep-exercises/1-wallet/ex2-classes.js

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,5 @@
11
import eurosFormatter from './euroFormatter.js';
22

3-
/*
4-
class Wallet {
5-
#name;
6-
#cash;
7-
8-
constructor(name, cash) {
9-
this.#name = name;
10-
this.#cash = cash;
11-
}
12-
13-
get name() {
14-
return this.#name;
15-
}
16-
17-
deposit(amount) {
18-
this.#cash += amount;
19-
}
20-
21-
withdraw(amount) {
22-
if (this.#cash - amount < 0) {
23-
console.log(`Insufficient funds!`);
24-
return 0;
25-
}
26-
27-
this.#cash -= amount;
28-
return amount;
29-
}
30-
31-
transferInto(wallet, amount) {
32-
console.log(
33-
`Transferring ${eurosFormatter.format(amount)} from ${this.name} to ${
34-
wallet.name
35-
}`
36-
);
37-
const withdrawnAmount = this.withdraw(amount);
38-
wallet.deposit(withdrawnAmount);
39-
}
40-
41-
reportBalance() {
42-
console.log(
43-
`Name: ${this.name}, balance: ${eurosFormatter.format(this.#cash)}`
44-
);
45-
}
46-
}
47-
48-
function main() {
49-
const walletJack = new Wallet('Jack', 100);
50-
const walletJoe = new Wallet('Joe', 10);
51-
const walletJane = new Wallet('Jane', 20);
52-
53-
walletJack.transferInto(walletJoe, 50);
54-
walletJane.transferInto(walletJoe, 25);
55-
56-
walletJane.deposit(20);
57-
walletJane.transferInto(walletJoe, 25);
58-
59-
walletJack.reportBalance();
60-
walletJoe.reportBalance();
61-
walletJane.reportBalance();
62-
}
63-
64-
main();
65-
*/
66-
673
class Wallet {
684
#name;
695
#cash;

Week4/prep-exercises/1-wallet/ex3-object.js

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,5 @@
11
import eurosFormatter from './euroFormatter.js';
22

3-
/*
4-
function createWallet(name, cash = 0) {
5-
return {
6-
_name: name,
7-
_cash: cash,
8-
9-
deposit: function (amount) {
10-
this._cash += amount;
11-
},
12-
13-
withdraw: function (amount) {
14-
if (this._cash - amount < 0) {
15-
console.log(`Insufficient funds!`);
16-
return 0;
17-
}
18-
19-
this._cash -= amount;
20-
return amount;
21-
},
22-
23-
transferInto: function (wallet, amount) {
24-
console.log(
25-
`Transferring ${eurosFormatter.format(amount)} from ${
26-
this._name
27-
} to ${wallet.getName()}`
28-
);
29-
const withdrawnAmount = this.withdraw(amount);
30-
wallet.deposit(withdrawnAmount);
31-
},
32-
33-
reportBalance: function () {
34-
console.log(
35-
`Name: ${this._name}, balance: ${eurosFormatter.format(this._cash)}`
36-
);
37-
},
38-
39-
getName: function () {
40-
return this._name;
41-
},
42-
};
43-
}
44-
45-
function main() {
46-
const walletJack = createWallet('Jack', 100);
47-
const walletJoe = createWallet('Joe', 10);
48-
const walletJane = createWallet('Jane', 20);
49-
50-
walletJack.transferInto(walletJoe, 50);
51-
walletJane.transferInto(walletJoe, 25);
52-
53-
walletJane.deposit(20);
54-
walletJane.transferInto(walletJoe, 25);
55-
56-
walletJack.reportBalance();
57-
walletJoe.reportBalance();
58-
walletJane.reportBalance();
59-
}
60-
61-
main();
62-
*/
63-
643
function createWallet(name, cash = 0) {
654
return {
665
_name: name,

Week4/prep-exercises/1-wallet/ex4-object-shared-methods.js

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,5 @@
11
import eurosFormatter from './euroFormatter.js';
22

3-
/*
4-
function deposit(amount) {
5-
this._cash += amount;
6-
}
7-
8-
function withdraw(amount) {
9-
if (this._cash - amount < 0) {
10-
console.log(`Insufficient funds!`);
11-
return 0;
12-
}
13-
14-
this._cash -= amount;
15-
return amount;
16-
}
17-
18-
function transferInto(wallet, amount) {
19-
console.log(
20-
`Transferring ${eurosFormatter.format(amount)} from ${
21-
this._name
22-
} to ${wallet.getName()}`
23-
);
24-
const withdrawnAmount = this.withdraw(amount);
25-
wallet.deposit(withdrawnAmount);
26-
}
27-
28-
function reportBalance() {
29-
console.log(
30-
`Name: ${this._name}, balance: ${eurosFormatter.format(this._cash)}`
31-
);
32-
}
33-
34-
function getName() {
35-
return this._name;
36-
}
37-
38-
function createWallet(name, cash = 0) {
39-
return {
40-
_name: name,
41-
_cash: cash,
42-
deposit,
43-
withdraw,
44-
transferInto,
45-
reportBalance,
46-
getName,
47-
};
48-
}
49-
50-
function main() {
51-
const walletJack = createWallet('Jack', 100);
52-
const walletJoe = createWallet('Joe', 10);
53-
const walletJane = createWallet('Jane', 20);
54-
55-
walletJack.transferInto(walletJoe, 50);
56-
walletJane.transferInto(walletJoe, 25);
57-
58-
walletJane.deposit(20);
59-
walletJane.transferInto(walletJoe, 25);
60-
61-
walletJack.reportBalance();
62-
walletJoe.reportBalance();
63-
walletJane.reportBalance();
64-
}
65-
66-
main();
67-
*/
68-
693
function deposit(amount) {
704
this._cash += amount;
715
}

Week4/prep-exercises/1-wallet/ex5-prototype.js

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,5 @@
11
import eurosFormatter from './euroFormatter.js';
22

3-
/*
4-
function Wallet(name, cash) {
5-
this._name = name;
6-
this._cash = cash;
7-
}
8-
9-
Wallet.prototype.deposit = function (amount) {
10-
this._cash += amount;
11-
};
12-
13-
Wallet.prototype.withdraw = function (amount) {
14-
if (this._cash - amount < 0) {
15-
console.log(`Insufficient funds!`);
16-
return 0;
17-
}
18-
19-
this._cash -= amount;
20-
return amount;
21-
};
22-
23-
Wallet.prototype.transferInto = function (wallet, amount) {
24-
console.log(
25-
`Transferring ${eurosFormatter.format(amount)} from ${
26-
this._name
27-
} to ${wallet.getName()}`
28-
);
29-
const withdrawnAmount = this.withdraw(amount);
30-
wallet.deposit(withdrawnAmount);
31-
};
32-
33-
Wallet.prototype.reportBalance = function () {
34-
console.log(
35-
`Name: ${this._name}, balance: ${eurosFormatter.format(this._cash)}`
36-
);
37-
};
38-
39-
Wallet.prototype.getName = function () {
40-
return this._name;
41-
};
42-
43-
function main() {
44-
const walletJack = new Wallet('Jack', 100);
45-
const walletJoe = new Wallet('Joe', 10);
46-
const walletJane = new Wallet('Jane', 20);
47-
48-
walletJack.transferInto(walletJoe, 50);
49-
walletJane.transferInto(walletJoe, 25);
50-
51-
walletJane.deposit(20);
52-
walletJane.transferInto(walletJoe, 25);
53-
54-
walletJack.reportBalance();
55-
walletJoe.reportBalance();
56-
walletJane.reportBalance();
57-
}
58-
59-
main();
60-
*/
61-
623
function Wallet(name, cash) {
634
this._name = name;
645
this._cash = cash;

0 commit comments

Comments
 (0)