-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.js
More file actions
37 lines (30 loc) · 758 Bytes
/
examples.js
File metadata and controls
37 lines (30 loc) · 758 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
35
36
37
let balance = 100;
function deposit(amount) {
balance += amount;
}
function withdraw(amount) {
balance -= amount;
}
withdraw(1000);
console.log(balance);
// Objetos Literales
const account = {
owner: 'Felipe',
ownerId: 12312,
balance: 100,
deposit(amount) {
if (amount <= 0) throw new Error('El monto debe de ser mayor a 0');
this.balance += amount;
return this.balance;
},
withdraw(amount) {
if (amount <= 0) throw new Error('El monto debe ser mayor a 0');
if (amount > this.balance) throw new Error('Fondos Insuficientes');
this.balance -= amount;
return this.balance;
},
};
console.log(account.balance); // 100
account.deposit(50); // 150
account.withdraw(70); // 80
console.log(account.balance); //80