Skip to content

Commit 2d18cde

Browse files
committed
classes
1 parent 80b8b54 commit 2d18cde

File tree

12 files changed

+206
-27
lines changed

12 files changed

+206
-27
lines changed

0x02-ES6_classes/0-main.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

0x02-ES6_classes/1-main.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

0x02-ES6_classes/10-car.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export default class Car {
2+
constructor(brand, motor, color) {
3+
this._brand = brand;
4+
this._motor = motor;
5+
this._color = color;
6+
}
7+
8+
static get [Symbol.species]() {
9+
return this;
10+
}
11+
12+
cloneCar() {
13+
return new this.constructor[Symbol.species]();
14+
}
15+
}

0x02-ES6_classes/100-evcar.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Car from './10-car';
2+
3+
export default class EVCar extends Car {
4+
constructor(brand, motor, color, range) {
5+
super(brand, motor, color);
6+
this._range = range;
7+
}
8+
9+
static get [Symbol.species]() {
10+
return Car;
11+
}
12+
13+
cloneCar() {
14+
return new this.constructor[Symbol.species]();
15+
}
16+
}

0x02-ES6_classes/2-main.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

0x02-ES6_classes/3-currency.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export default class Currency {
2+
constructor(code, name) {
3+
this.code = code;
4+
this.name = name;
5+
}
6+
7+
get code() {
8+
return this._code;
9+
}
10+
11+
get name() {
12+
return this._name;
13+
}
14+
15+
set code(code) {
16+
if (typeof code === 'string') {
17+
this._code = code;
18+
} else {
19+
throw new Error('Code must be a string.');
20+
}
21+
}
22+
23+
set name(name) {
24+
if (typeof name === 'string') {
25+
this._name = name;
26+
} else {
27+
throw new Error('Name must be a string.');
28+
}
29+
}
30+
31+
displayFullCurrency() {
32+
return `${this._name} (${this._code})`;
33+
}
34+
}

0x02-ES6_classes/4-pricing.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import Currency from './3-currency';
2+
3+
export default class Pricing {
4+
constructor(amount, currency) {
5+
this.amount = amount;
6+
this.currency = currency;
7+
}
8+
9+
get amount() {
10+
return this._amount;
11+
}
12+
13+
get currency() {
14+
return this._currency;
15+
}
16+
17+
set amount(amount) {
18+
if (typeof amount === 'number') {
19+
this._amount = amount;
20+
} else {
21+
throw new Error('Amount must be a number');
22+
}
23+
}
24+
25+
set currency(currency) {
26+
if (currency instanceof Currency) {
27+
this._currency = currency;
28+
} else {
29+
throw new Error('Currency must be an instance of currency');
30+
}
31+
}
32+
33+
displayFullPrice() {
34+
return `${this._amount} ${this._currency.displayFullCurrency()}`;
35+
}
36+
37+
static convertPrice(amount, conversionRate) {
38+
return amount * conversionRate;
39+
}
40+
}

0x02-ES6_classes/5-building.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export default class Building {
2+
constructor(sqft) {
3+
this._sqft = sqft;
4+
this.evacuationWarningMessage();
5+
}
6+
7+
get sqft() {
8+
return this._sqft;
9+
}
10+
11+
evacuationWarningMessage() {
12+
if (this.constructor.name !== 'Building') {
13+
throw new Error('Class extending Building must override evacuationWarningMessage');
14+
}
15+
}
16+
}

0x02-ES6_classes/6-sky_high.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Building from './5-building';
2+
3+
export default class SkyHighBuilding extends Building {
4+
constructor(sqft, floors) {
5+
super(sqft);
6+
this._floors = floors;
7+
}
8+
9+
get floors() {
10+
return this._floors;
11+
}
12+
13+
evacuationWarningMessage() {
14+
return `Evacuate slowly the ${this._floors} floors`;
15+
}
16+
}

0x02-ES6_classes/7-airport.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default class Airport {
2+
constructor(name, code) {
3+
this._name = name;
4+
this._code = code;
5+
}
6+
7+
get [Symbol.toStringTag]() {
8+
return this._code;
9+
}
10+
}

0x02-ES6_classes/8-hbtn_class.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export default class HolbertonClass {
2+
constructor(size, location) {
3+
this._size = size;
4+
this._location = location;
5+
}
6+
7+
[Symbol.toPrimitive](type) {
8+
if (type === 'string') {
9+
return this._location;
10+
}
11+
return this._size;
12+
}
13+
}

0x02-ES6_classes/9-hoisting.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
export class HolbertonClass {
2+
constructor(year, location) {
3+
this._year = year;
4+
this._location = location;
5+
}
6+
7+
get year() {
8+
return this._year;
9+
}
10+
11+
get location() {
12+
return this._location;
13+
}
14+
}
15+
16+
export class StudentHolberton {
17+
constructor(firstName, lastName, holbertonClass) {
18+
this._firstName = firstName;
19+
this._lastName = lastName;
20+
this._holbertonClass = holbertonClass;
21+
}
22+
23+
get fullName() {
24+
return `${this._firstName} ${this._lastName}`;
25+
}
26+
27+
get holbertonClass() {
28+
return this._holbertonClass;
29+
}
30+
31+
get fullStudentDescription() {
32+
return `${this.fullName} - ${this.holbertonClass.year} - ${this.holbertonClass.location}`;
33+
}
34+
}
35+
36+
const class2019 = new HolbertonClass(2019, 'San Francisco');
37+
const class2020 = new HolbertonClass(2020, 'San Francisco');
38+
39+
const student1 = new StudentHolberton('Guillaume', 'Salva', class2020);
40+
const student2 = new StudentHolberton('John', 'Doe', class2020);
41+
const student3 = new StudentHolberton('Albert', 'Clinton', class2019);
42+
const student4 = new StudentHolberton('Donald', 'Bush', class2019);
43+
const student5 = new StudentHolberton('Jason', 'Sandler', class2019);
44+
45+
const listOfStudents = [student1, student2, student3, student4, student5];
46+
export default listOfStudents;

0 commit comments

Comments
 (0)