Skip to content

Commit 1bebaaa

Browse files
committed
2 parents 9329dbc + 26ee43d commit 1bebaaa

File tree

7 files changed

+111
-22
lines changed

7 files changed

+111
-22
lines changed

src/live/cards.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,39 @@
11
'use strict';
22

3-
const CARD_SUITES = [
4-
{ symbol: '♦️', name: 'tiles' },
5-
{ symbol: '♠️', name: 'pikes' },
3+
const CARD_SUITS = [
4+
{ symbol: '♦️', name: 'diamond' },
5+
{ symbol: '♠️', name: 'spades' },
66
{ symbol: '♥️', name: 'hearts' },
7-
{ symbol: '♣️', name: 'clovers' },
7+
{ symbol: '♣️', name: 'clubs' },
88
];
99

1010
const CARD_RANKS = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A'];
11+
12+
class Card {
13+
constructor(symbol, rank) {
14+
this.symbol = symbol;
15+
this.rank = rank;
16+
}
17+
18+
getCard() {
19+
return this.symbol + this.rank;
20+
}
21+
}
22+
23+
class CardDeck {
24+
constructor() {
25+
this.allCards = [];
26+
CARD_SUITS.forEach(suit => {
27+
const cards = CARD_RANKS.map(rank => new Card(suit.symbol, rank));
28+
this.allCards = this.allCards.concat(cards);
29+
});
30+
}
31+
32+
getCards() {
33+
return this.allCards;
34+
}
35+
}
36+
37+
const myCards = new CardDeck();
38+
console.log(myCards.getCards());
39+

src/live/dog.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
3+
class Animal {
4+
constructor(type, name, color, numLegs, sound) {
5+
this.type = type;
6+
this.name = name;
7+
this.color = color;
8+
this.numLegs = numLegs;
9+
this.sound = sound;
10+
}
11+
12+
makeSound() {
13+
console.log(this.sound);
14+
}
15+
}
16+
17+
class Dog extends Animal {
18+
constructor(name, color) {
19+
super('dog', name, color, 4, 'waf waf!');
20+
}
21+
}
22+
23+
class Cat extends Animal {
24+
constructor(name, color) {
25+
super('cat', name, color, 4, 'meow!');
26+
}
27+
}
28+
29+
const myDog = new Dog('Tarzan', 'brown');
30+
const myCat = new Cat('Binky', 'black');
31+
32+
myDog.makeSound();
33+
myCat.makeSound();
34+
35+

src/live/this.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
4+
const myCat = {
5+
name: 'Binky',
6+
color: 'black',
7+
greet(greeting, closing) {
8+
console.log(greeting + ' ' + this.name + closing);
9+
}
10+
};
11+
12+
myCat.greet('Hello', ', where have you been????');
13+
// // greetFn('Hello', ', where have you been?');
14+
15+
// greetFn.call(myCat, 'Hello', ', where have you been?');
16+
// greetFn.apply(myCat, ['Hello', ', where have you been?']);
17+
18+
myCat.greet('Hello', '???');
19+
20+
const greet2 = myCat.greet.bind(myCat);
21+
// console.log(greetFn === myCat.greet);
22+
23+
greet2('Hello', '!!!!');
24+

src/week3/cards-node/1-cards.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict';
22

3-
const CARD_SUITES = [
4-
{ symbol: '♦️', name: 'tiles' },
5-
{ symbol: '♠️', name: 'pikes' },
3+
const CARD_SUITS = [
4+
{ symbol: '♦️', name: 'diamond' },
5+
{ symbol: '♠️', name: 'spades' },
66
{ symbol: '♥️', name: 'hearts' },
7-
{ symbol: '♣️', name: 'clovers' },
7+
{ symbol: '♣️', name: 'clubs' },
88
];
99

1010
const CARD_RANKS = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A'];
@@ -18,7 +18,7 @@ class Card {
1818
this.rank = rank;
1919
}
2020

21-
getCardFace() {
21+
getCard() {
2222
return `${this.symbol}${this.rank}`;
2323
}
2424
}
@@ -29,7 +29,7 @@ class Card {
2929
class CardDeck {
3030
constructor() {
3131
this.allCards = [];
32-
CARD_SUITES.forEach(suit => {
32+
CARD_SUITS.forEach(suit => {
3333
const cards = CARD_RANKS.map(rank => new Card(suit.symbol, rank));
3434
this.allCards = this.allCards.concat(cards);
3535
});
@@ -49,7 +49,7 @@ class CardDeck {
4949

5050
render(cards) {
5151
const text = cards
52-
.map(card => card.getCardFace())
52+
.map(card => card.getCard())
5353
.join(' ');
5454

5555
console.log(text);

src/week3/cards-node/2-cards.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ const FG = {
66
green: '\x1b[32m'
77
};
88

9-
const CARD_SUITES = [
10-
{ symbol: '♦️', color: FG.red, name: 'tiles' },
11-
{ symbol: '♠️', color: FG.white, name: 'pikes' },
9+
const CARD_SUITS = [
10+
{ symbol: '♦️', color: FG.red, name: 'diamond' },
11+
{ symbol: '♠️', color: FG.white, name: 'spades' },
1212
{ symbol: '♥️', color: FG.red, name: 'hearts' },
13-
{ symbol: '♣️', color: FG.white, name: 'clovers' },
13+
{ symbol: '♣️', color: FG.white, name: 'clubs' },
1414
];
1515

1616
const CARD_RANKS = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A'];
@@ -25,7 +25,7 @@ class Card {
2525
this.rank = rank;
2626
}
2727

28-
getCardFace() {
28+
getCard() {
2929
return `${this.color}${this.symbol}${this.rank}${FG.white}`;
3030
}
3131
}
@@ -36,7 +36,7 @@ class Card {
3636
class CardDeck {
3737
constructor() {
3838
this.allCards = [];
39-
CARD_SUITES.forEach(suit => {
39+
CARD_SUITS.forEach(suit => {
4040
const suitCards = CARD_RANKS.map(rank => new Card(suit.symbol, suit.color, rank));
4141
this.allCards = this.allCards.concat(suitCards);
4242
});
@@ -56,7 +56,7 @@ class CardDeck {
5656

5757
render(cards) {
5858
const text = cards
59-
.map(card => card.getCardFace())
59+
.map(card => card.getCard())
6060
.join(' ');
6161

6262
console.log(text);

src/week3/cards-web/CardDeck.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
{
3-
const CARD_SUITES = [
3+
const CARD_SUITS = [
44
{ symbol: '♦️', color: 'red' },
55
{ symbol: '♠️', color: 'black' },
66
{ symbol: '♥️', color: 'red' },
@@ -12,7 +12,7 @@
1212
class CardDeck {
1313
constructor() {
1414
this.allCards = [];
15-
CARD_SUITES.forEach(suit => {
15+
CARD_SUITS.forEach(suit => {
1616
const suitCards = CARD_RANKS.map(rank => window.createCard(suit.symbol, suit.color, rank));
1717
this.allCards = this.allCards.concat(suitCards);
1818
});

src/week3/this/2-new/app.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
// 'use strict';
1+
'use strict';
22

33
function Dog() {
4+
console.log(this);
45
this.name = 'Tarzan';
56
this.color = 'brown';
67
this.numLegs = 4;
78
}
89

9-
const myDog = Dog();
10+
const myDog = new Dog();
1011
console.log(myDog);

0 commit comments

Comments
 (0)