You must select a tag to post in this category. Please find the tag relating to the section of the course you are on E.g. loops, learn-compatibility
When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!
If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer!
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(){
const sumRatings = this._ratings.reduce((accumulator,currentValue) => accumulator + currentValue, 0);
return Math.floor(sumRatings / this._ratings.length);
}
addRating(value){
if(value >= 1 && value <= 5){
this._ratings.push(value);
} else {
return 'the input must not be less than one and not more than five.';
}
}
}
class Book extends Media{
constructor(author, title, pages){
super(title);
this._author = author;
this._pages = pages;
}
get author(){
return this._author;
}
get pages(){
return this._pages;
}
}
class Movie extends Media{
constructor(director, title, runTime){
super(title);
this._director = director;
this._runTime = runTime;
this._movieCast = ;
}
get director(){
return this._director;
}
get runTime(){
return this._runTime;
}
get movieCast(){
return this._movieCast;
}
addCast(value){
this._movieCast.push(value);
}
}
const historyOfEverything = new Book(‘Bill Bryson’, ‘A Short History of Nearly Everything’, 544);
historyOfEverything.isCheckedOut = true;
historyOfEverything.toggleCheckOutStatus();
console.log(historyOfEverything.isCheckedOut);
historyOfEverything.addRating(4);
historyOfEverything.addRating(5);
historyOfEverything.addRating(5);
console.log(historyOfEverything.getAverageRating());
const speed = new Movie(‘Jan de Bont’, ‘Speed’, 116);
speed.isCheckedOut = true;
speed.toggleCheckOutStatus();
console.log(speed.isCheckedOut);
speed.addRating(1);
speed.addRating(1);
speed.addRating(5);
console.log(speed.getAverageRating());
speed.addCast(‘Keanu Reeves’);
speed.addCast(‘Dennis Hopper’);
speed.addCast(‘Sandra Bullock’);
speed.addCast(‘Joe Morton’);
console.log(speed.movieCast);
class CD extends Media{
constructor(artist, title){
super(title);
this._artist = artist;
this._songTitles = ;
}
get artist(){
return this._artist;
}
get songTitles(){
return this._songTitles;
}
addSongs(value){
this._songTitles.push(value);
}
shuffle(){
return this._songTitles.sort(()=> 0.5 - Math.random());
}
}
const origenYEsenciaCD = new CD(‘Jesus Adrian Romero’, ‘Origen y Esencia’);
console.log(origenYEsenciaCD.artist);
console.log(origenYEsenciaCD.title);
origenYEsenciaCD.addSongs(‘Mundo Interior’);
origenYEsenciaCD.addSongs(‘Se Quedó Conmigo’);
origenYEsenciaCD.addSongs(‘Olvidé Cuidar Mi Huerto’);
origenYEsenciaCD.addSongs(‘Una Casa Vacía’);
origenYEsenciaCD.addSongs(‘El Anhelo De Mi Voz’);
origenYEsenciaCD.addSongs(‘LLévame A La Montaña’);
origenYEsenciaCD.addSongs(‘Que Seas Mi Hogar Feat (Reyli Barba)’);
origenYEsenciaCD.addSongs(‘Cómplices’);
origenYEsenciaCD.addSongs(‘Mi Fe Se Gastó’);
origenYEsenciaCD.addSongs(‘Estar A Tus Pies’);
origenYEsenciaCD.addSongs(‘Ahora Vuelvo’);
origenYEsenciaCD.addSongs(‘Duele El Eco’);
console.log(origenYEsenciaCD.songTitles);
console.log(origenYEsenciaCD.shuffle());
class Catalog {
constructor(){
this._media = ;
}
get media(){
return this._media;
}
addMedia(item){
this._media.push(item);
}
removeMedia(item){
const index = this._media.indexOf(item);
if(index !== -1){
this._media.splice(index, 1);
}
}
}
const catalog = new Catalog();
catalog.addMedia(historyOfEverything);
catalog.addMedia(speed);
catalog.addMedia(origenYEsenciaCD);
console.log(catalog.media);