I am just playing around now after finishing the project since.
I set up and entire string with the media type, the title, run time/pages,
author/director/artist, what it is rated, and whether it is checked out or available for when I call printString().
I am running into an undefined at the end and the printString at the beginning.
can anyone help me fix this code?
Returning:
Output-only Terminal
Output:
Dr. Jekyll and Mr. Hyde is avalible. Speek to an associate for assistance finding this Book.
Dr. Jekyll and Mr. Hyde, written by Robert Louis Stevenson, Vladimir Nabokov (Introduction), Dan Chaon (Afterword), is 139 pages. Dr. Jekyll and Mr. Hyde is rated 3 stars by readers. undefined
Grave is avalible. Speek to an associate for assistance finding this CD.
Grave, by Endless Procession Of Souls, has 10 songs. The songs on this album are Dystopia, Amongst Marble and the Dead, Disembodied Steps, Flesh Epistle, Passion of the Weak, Winds of Chains, Encountering the Divine, Perimortem. Plague of Nations, Plague of Nations, Epos.
Grave is rated 4 stars by listeners. undefined
Marley & Me is checked out. Talk to an associate to get on a wait list for this Movie.
Marley & Me, directed by David Frankel, staring , has a 115 minute run time. Marley & Me is rated 4 stars by watchers. undefined
//parent class
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;
}
toggleCheckOutStatus() {
this._isCheckedOut = !this.isCheckedOut;
}
getAverageRating() {
if (this.ratings.length === 0) {
return 0;
}
const sum = this.ratings.reduce((acc, val) => acc + val, 0);
return Math.round(sum / this.ratings.length);
}
addRating(rating) {
if (rating >= 1 && rating <= 5) {
this.ratings.push(rating);
} else {
console.error(
`Sorry, the Rating for ${this.title} must be between 1 and 5.`
);
}
}
set isCheckedOut(checkedIn) {
this._isCheckedOut = checkedIn;
}
printString() {
if (this.isCheckedOut) {
console.log(
`${this.title} is checked out. Talk to an associate to get on a wait list for this ${this.constructor.name}.`
);
} else {
console.log(
`${this.title} is avalible. Speek to an associate for assistance finding this ${this.constructor.name}.`
);
}
}
info() {
if (this instanceof Book)
console.log(
`${this.title}, written by ${this.author}, is ${this.pages} pages. ${
this.title
} is rated ${this.getAverageRating()} stars by readers. ` +
this.printString()
);
else if (this instanceof Movie)
console.log(
`${this.title}, directed by ${this.director}, staring ${
this.cast
}, has a ${this.runTime} minute run time. ${
this.title
} is rated ${this.getAverageRating()} stars by watchers. ` +
this.printString()
);
else if (this instanceof CD)
console.log(
`${this.title}, by ${this.artist}, has ${
this.songs
} songs. The songs on this album are ${this.songTitles}.
${this.title} is rated ${this.getAverageRating()} stars by listeners. ` +
this.printString()
);
else
console.log(
`This title is not avalibe a this location. Please ask an associate for assisance.`
);
}
}
//child classes
class Book extends Media {
constructor(title, author, pages) {
super(title);
this._author = author;
this._pages = pages;
}
get author() {
return this._author;
}
get pages() {
return this._pages;
}
}
class Movie extends Media {
constructor(title, director, runTime, cast) {
super(title);
this._director = director;
this._runTime = runTime;
this._cast = [];
}
get director() {
return this._director;
}
get runTime() {
return this._runTime;
}
get cast() {
return this._cast;
}
}
class CD extends Media {
constructor(title, artist, songs, songTitles) {
super(title);
this._artist = artist;
this._songs = songs;
this._songTitles = songTitles;
}
get artist() {
return this._artist;
}
get songs() {
return this._songs;
}
get songTitles() {
return this._songTitles;
}
}
//method for information pull
//instances
const historyOfEverything = new Book(
"A Short History of Nearly Everything",
"Bill Bryson",
544
);
const theGreatGatsby = new Book("F. Scott Fitzgerald", "The Great Gatsby", 180);
const jekyllAndHyde = new Book(
"Dr. Jekyll and Mr. Hyde",
"Robert Louis Stevenson, Vladimir Nabokov (Introduction), Dan Chaon (Afterword)",
139
);
const sherlockHolmes = new Book(
"The Complete Sherlock Holmes",
"Arthur Conan Doyle",
1796
);
const speed = new Movie(
"Speed",
"Jan de Bont",
116,
"Keanu Reeves, Dennis Hopper, Sandra Bullock, Joe Morton, Jeff Daniels"
);
const snowWhite = new Movie(
"Snow White and the Seven Dwarfs",
"David Hand",
79,
"Adriana Caselotti, Harry Stockwell, Lucille LaVerne, Moroni Olsen, Billy Gilbert, Billy Gilbert, Pinto Colvig, Otis Harlan, Scotty Mattraw, Roy Atwell"
);
const theEdge = new Movie(
"The Edge",
"Lee Tamahori",
212,
"Anthony Hopkins, Alec Baldwin, Elle Macpherson, Harold Perrineau"
);
const marley = new Movie(
"Marley & Me",
"David Frankel",
115,
"Owen Wilson, Jennifer Aniston"
);
const endlessProcessionOfSouls = new CD(
"Grave",
"Endless Procession Of Souls",
10,
"Dystopia, Amongst Marble and the Dead, Disembodied Steps, Flesh Epistle, Passion of the Weak, Winds of Chains, Encountering the Divine, Perimortem. Plague of Nations, Plague of Nations, Epos"
);
const comeGetIt = new CD(
"Rick James",
"Come Get It!",
9,
"Stone City Band, Hi!, You And I, Sexy Lady, Dream Maker, Be My Lady, Mary Jane, Hollywood, Stone City Band, Bye!, You And I - Extended M+M Mix"
);
const aTribeCalledRed = new CD(
"The Halluci Nation",
"A Tribe Called Red",
9,
"Electric Pow Wow Drum, Look at This - Remix, Northern Cree - Red Skin Girl - A Tribe Called Red Remix, Woodcarver, Good to Go, Munchi - Shottas - A Tribe Called Red Socacore Remix, Native Puppy Love, Moombahwow, Intertribal N.1"
);
const bachImprovisations = new CD(
"Ira Stein",
"Bach Improvisations",
9,
"Cantata No. 122, Cantata No. 11, Cantata No. 31, Christmas Oratorio , Choral for 4 voices (Liebster jesu), Choral for 4 voices (O Mensch), Chorale for 4 voices Wir glauben all en einen Gott), Jesu, Chorale for 4 voices (Komm)"
);
historyOfEverything.toggleCheckOutStatus();
theGreatGatsby.toggleCheckOutStatus();
historyOfEverything.addRating(5);
historyOfEverything.addRating(3);
historyOfEverything.addRating(5);
theGreatGatsby.addRating(4);
theGreatGatsby.addRating(3);
theGreatGatsby.addRating(4);
theGreatGatsby.addRating(2);
theGreatGatsby.addRating(4);
jekyllAndHyde.addRating(5);
jekyllAndHyde.addRating(4);
jekyllAndHyde.addRating(4);
jekyllAndHyde.addRating(5);
jekyllAndHyde.addRating(1);
jekyllAndHyde.addRating(5);
jekyllAndHyde.addRating(3);
jekyllAndHyde.addRating(1);
jekyllAndHyde.addRating(2);
jekyllAndHyde.addRating(4);
sherlockHolmes.addRating(1);
sherlockHolmes.addRating(5);
sherlockHolmes.addRating(5);
sherlockHolmes.addRating(5);
speed.toggleCheckOutStatus();
snowWhite.toggleCheckOutStatus();
marley.toggleCheckOutStatus();
speed.addRating(1);
speed.addRating(1);
speed.addRating(5);
snowWhite.addRating(5);
snowWhite.addRating(3);
snowWhite.addRating(5);
snowWhite.addRating(4);
theEdge.addRating(5);
theEdge.addRating(1);
theEdge.addRating(2);
theEdge.addRating(4);
theEdge.addRating(4);
marley.addRating(5);
marley.addRating(5);
marley.addRating(5);
marley.addRating(5);
marley.addRating(5);
marley.addRating(4);
marley.addRating(4);
marley.addRating(1);
endlessProcessionOfSouls.addRating(5);
endlessProcessionOfSouls.addRating(4);
endlessProcessionOfSouls.addRating(2);
endlessProcessionOfSouls.addRating(4);
endlessProcessionOfSouls.addRating(4);
comeGetIt.addRating(5);
comeGetIt.addRating(4);
comeGetIt.addRating(3);
comeGetIt.addRating(5);
comeGetIt.addRating(4);
aTribeCalledRed.addRating(2);
aTribeCalledRed.addRating(4);
aTribeCalledRed.addRating(4);
aTribeCalledRed.addRating(3);
bachImprovisations.addRating(5);
bachImprovisations.addRating(4);
bachImprovisations.addRating(3);
bachImprovisations.addRating(3);
bachImprovisations.addRating(2);
jekyllAndHyde.info();
endlessProcessionOfSouls.info();
marley.info();