Https://www.codecademy.com/paths/web-development/tracks/webdev-intermediate-javascript/modules/learn-javascript-classes/projects/build-a-library

https://www.codecademy.com/paths/web-development/tracks/webdev-intermediate-javascript/modules/learn-javascript-classes/projects/build-a-library

Hello!
I do not know why I keep getting a syntax error from 'super" keyword, from subclasses Book and Movies. Located on first line of every Constructor. Anyone guess ??

//parent class Media
//tittle the only property in commun with 3 sub classes that doesn t have a default value.
class Media {
Constructor(title) {
this._tittle = title;
this._isCheckedOut = false;
this._ratings = ;
}
get tittle() {
return this._title;
}
//isCheckedOut needs a “value”, as we need to assign something to this.
get isCheckedOut() {
return this._isCheckedOut;
}
get ratings() {
return this._ratings;
}
toggleCheckOutStatus() {
this._isCheckedOut = !this._isCheckedOut;
}
getAverageRating() {
let ratingsSum =
this.ratings.reduce((currentSum, rating) =>
currentSum + rating, 0);
return ratingsSum / this._ratings.length;
}

addRating(value) {
this.ratings.push(value)
}

set isCheckedOut(value) {
this._isCheckedOut = value;
}
}
//Sub class Book (exentintion of parent class Media)
//Author, title and pages are 3 properties within Book, therefore go as arguments for constructor.
class Book extends Media {
Constructor(author, title, pages) {
super(title);
this._author = author;
this._pages = 0;
}

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 = 0;
}

get director() {
return this._director;
}
get runTime() {
return this._runTime;
}
}
const historyOfEverything = new Book(‘Bill Bryson’, ‘A Short History of Nearly Everything’, 544);
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.toggleCheckOutStatus();
console.log(speed.isCheckedOut());
speed.addRating(1);
speed.addRating(1);
speed.addRating(5);
console.log(speed.getAverageRating());

Keywords are not to be capitalized, only the class name is written thus.

constructor(author, title, pages)

Thank you!
By the way, now there is now an error with .push(), on parent class media. What s wrong ?

addRating(value) {
this.ratings.push(value);
}

Push it onto the backing variable, not the get() variable.

this._ratings.push(value);

I am afraid I do not follow you. What do you mean by backing variable ?
The video shows ‘this.ratings.push(value);’, without underline.

updated code below:

//parent class Media
//tittle the only property in commun with 3 sub classes that doesn t have a default value.
class Media {
  Constructor(title) {
    this._tittle = title;
    this._isCheckedOut = false;
    this._ratings = [];
  }
  get title() {
    return this._title;
  }
  //isCheckedOut needs a "value", as we need to assign something to this.
  get isCheckedOut() {
    return this._isCheckedOut;
  }
  get ratings() {
    return this._ratings;
  }
  toggleCheckOutStatus() {
    this._isCheckedOut = !this._isCheckedOut;
  }
  
   set isCheckedOut(value) {
    this._isCheckedOut = value;
  }
  
  getAverageRating() {
    let ratingsSum = 
    this.ratings.reduce((currentSum, rating) => 
    currentSum + rating, 0);
        return ratingsSum / this._ratings.length;
  }
    
    addRating(value) {
    this.ratings.push(value);
  }
}
//Sub class Book (exentintion of parent class Media)
//Author, title and pages are 3 properties within Book, therefore go as arguments for constructor. 
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 = 0;
  }
  
   get director() {
    return this._director;
  }
  get runTime() {
    return this._runTime;
  }  
}
const historyOfEverything = new Book('Bill Bryson', 'A Short History of Nearly Everything', 544);
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.toggleCheckOutStatus();
console.log(speed.isCheckedOut());
speed.addRating(1);
speed.addRating(1);
speed.addRating(5);
console.log(speed.getAverageRating());

Did you try the way I showed in the example?

More typos. constructor and _title.

I gotcha!!! Finally, the code up and running just fine. Tks a lot!

script.js
class Media {
  constructor(title) {
    this._title = title;
    this._isCheckedOut = false;
    this._ratings = [];
  }
  get title() {
    return this._title;
  }
  //isCheckedOut needs a "value", as we need to assign something to this.
  get isCheckedOut() {
    return this._isCheckedOut;
  }
  get ratings() {
    return this._ratings;
  }
  toggleCheckOutStatus() {
    this._isCheckedOut = !this._isCheckedOut;
  }
  
   set isCheckedOut(value) {
    this._isCheckedOut = value;
  }
  
  getAverageRating() {
    let ratingsSum = 
    this.ratings.reduce((currentSum, rating) => 
    currentSum + rating, 0);
        return ratingsSum / this._ratings.length;
  }
    
    addRating(value) {
    this.ratings.push(value);
  }
}
//Sub class Book (exentintion of parent class Media)
//Author, title and pages are 3 properties within Book, therefore go as arguments for constructor. 
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 = 0;
  }
  
   get director() {
    return this._director;
  }
  get runTime() {
    return this._runTime;
  }  
}
const historyOfEverything = new Book('Bill Bryson', 'A Short History of Nearly Everything', 544);
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.toggleCheckOutStatus();
console.log(speed.isCheckedOut);
speed.addRating(1);
speed.addRating(1);
speed.addRating(5);
console.log(speed.getAverageRating());
1 Like