You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
767 B
34 lines
767 B
class MoneyManager { |
|
constructor(startMoney = null) { |
|
this.money = startMoney ?? this.getSavedMoney(); |
|
return this.saveMoney(); |
|
} |
|
|
|
saveMoney() { |
|
localStorage.setItem('money', String(this.money)); |
|
return this.getSavedMoney(); |
|
} |
|
|
|
getSavedMoney() { |
|
this.money = Number(localStorage.getItem('money') ?? 0); |
|
return this.money; |
|
} |
|
|
|
add(amount = 0) { |
|
this.money += amount; |
|
return this.saveMoney(); |
|
} |
|
|
|
sub(amount = 0) { |
|
this.money -= amount; |
|
return this.saveMoney(); |
|
} |
|
|
|
getAmount() { |
|
return this.money; |
|
} |
|
|
|
getAmountFormatted() { |
|
return Intl.NumberFormat('de-DE', {style: 'currency', currency: 'EUR'}).format(this.money); |
|
} |
|
} |