A simple team exercise
Create a pocket object that can contain coins ๐ฐ and trinkets ๐ฟ. The pocket allows users to buy()
trinkets for 10 coins, and sell()
trinkets for 8 coins. You can also return the number of coins()
or trinkets()
.
You cannot have a negative number of coins or trinkets.
const pocket = PocketFactory({
coins: 500,
trinkets: 2
});
Purchase 5 trinkets:
pocket.buyTrinkets(5);
Inspect pocket after purchase transaction:
pocket.getPocketedTrinkets(); // 7
pocket.getPocketedCoins(); // 450
Sell a single trinket:
pocket.sellTrinkets();
Inspect transaction history:
let history = pocket.getTransactionHistory();
console.table(history);
index | description | timestamp |
---|---|---|
0 | Account initiation | 2020-11-18T04:58:08.711Z |
1 | Purchased 5 trinkets for 50 coins | 2020-11-18T04:58:14.706Z |
2 | Sold 1 trinkets for 8 coins | 2020-11-18T04:58:20.686Z |