-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJukeBox.js
More file actions
50 lines (48 loc) · 1.25 KB
/
JukeBox.js
File metadata and controls
50 lines (48 loc) · 1.25 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
class Song{
constructor(Artist,Genre){
this.artist = Artist;
this.genre = Genre;
}
}
class JukeBox{
constructor(storage){
this.playing = null;
this.storage = storage;
this.number = 0;
this.records = {};
}
add(Title,Artist,Genre){
if (this.records[Title] !== undefined){
throw new Error('This song is already in the system');
}
if (this.number < this.storage){
if (this.records[Title] === undefined){
this.records[Title] = new Song(Artist,Genre);
this.number++;
}
} else {
throw new Error('Their are too many songs inside of the system');
}
}
remove(Title){
if (this.records[Title]){
delete this.records[Title];
this.number--;
} else {
throw new Error('this song is not in the system');
}
}
play(Title){
if (this.records[Title]){
this.playing = Title;
} else {
throw new Error('This song is not in the system');
}
}
}
var jukeBox = new JukeBox(10);
jukeBox.add('Cry me a River','Justin Timberlake','Pop');
jukeBox.add('Despacito','Justin Bieber','Pop');
jukeBox.remove('Despacito');
jukeBox.play('Cry me a River');
console.log(jukeBox);