-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuildALibrary.js
More file actions
132 lines (108 loc) · 2.79 KB
/
BuildALibrary.js
File metadata and controls
132 lines (108 loc) · 2.79 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
class Media {
constructor(title){
this._title = title;
this._isCheckedOut = false;
this._ratings = [];
}
get title(){
return this._title;
}
get isCheckedOut(){
return this._isCheckedOut;
}
get ratings(){
return this._ratings;
}
set isCheckedOut(value) {
this._isCheckedOut = value;
}
toggleCheckOutStatus(){
this.isCheckedOut = !this.isCheckedOut;
}
getAverageRating(){
let ratingsSum = this.ratings.reduce((accumulator, rating) =>
accumulator + rating);
return ratingsSum/this.ratings.length;
}
addRating(value){
this.ratings.push(value);
}
}
class Book extends Media {
constructor(author, title, pages) {
super(title);
this._author = author;
this._pages = pages;
}
get author() {
return this._author;
}
get page() {
return this._pages;
}
}
// add movie class, extension of media
class Movie extends Media {
constructor(director, title, runTime){
super(title);
this._director = director;
this._runTime = runTime;
}
get director(){
return this._director;
}
get runTime(){
return this._runTime;
}
}
// add additional class CD
class CD extends Media {
constructor(artist, title, songs){
super(title);
this._artist = artist;
this._songs = [];
}
get artist(){
return this._artist;
}
get songs(){
return this._songs;
}
song(value){
this.songs.push(value);
}
}
//Create new instance of book
const historyOfEverything = new Book ("Bill Bryson", "A Short History
of Nearly Everything", 544);
historyOfEverything.toggleCheckOutStatus();
console.log(historyOfEverything.isCheckedOut);
// Add ratings to the books
historyOfEverything.addRating(4);
historyOfEverything.addRating(5);
historyOfEverything.addRating(5);
console.log(historyOfEverything.getAverageRating());
//Create new instance of movie
const speed = new Movie("Jan de Bont", "Speed", 116);
speed.toggleCheckOutStatus();
console.log(speed.isCheckedOut);
// Add ratings to the movie
speed.addRating(1);
speed.addRating(1);
speed.addRating(5);
console.log(speed.getAverageRating());
//Create new instance of CD
const temsAlbum = new CD("Tems", "If Orange Was A Place", "Vibe Out" )
temsAlbum.toggleCheckOutStatus();
console.log(temsAlbum.isCheckedOut);
temsAlbum.addRating(5);
temsAlbum.addRating(4);
temsAlbum.addRating(5);
// Add songs to the album
temsAlbum.song("Avoid Things");
temsAlbum.song("Vibe Out");
temsAlbum.song("Crazy Tings");
temsAlbum.song("Replay");
temsAlbum.song("Found");
console.log(temsAlbum.getAverageRating());
console.log(temsAlbum);