-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript-notes.js
More file actions
66 lines (52 loc) · 1.28 KB
/
script-notes.js
File metadata and controls
66 lines (52 loc) · 1.28 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//class format example
class BankAccount {
constructor (clientName, currency) {
this.clientName = clientName;
this.currency = currency;
this.balance = 0.0;
}
showBalance() {
return `${this.currency} ${this.balance}`;
}
withdrawMoney(amount) {
if (amount <= this.balance) {
this.balance -= amount;
} else {
throw new Error('not enough funds');
}
}
depositMoney(amount) {
this.balance += amount
}
}
let account1 = new BankAccount('mike', '$');
account1.depositMoney(100);
account1.withdrawMoney(25);
account1.showBalance()
// $ 75
//below talks about class extending, and supers
class Product {
constructor(name, price) {
this.name = name;
this.price = price;
}
nameAndPrice() {
console.log(
"The product's name is: " + this.name,
"and the product's price is: " + this.price
);
}
}
class Electronic extends Product {
constructor(name, price, brand) {
super(name, price);
this.brand = brand;
}
}
let banana = new Product("Banana", 2);
banana.nameAndPrice();
let mac = new Electronic("Mac", 800, "Apple");
mac.nameAndPrice();
// The product's name is: Banana and the product's price is: 2
// The product's name is: Mac and the product's price is: 200
//CANVAS ANIMATION NOTES - CODE ALONG