Help me for this project i cant get where i go wrong

Welcome to the Get Help category!

This is where you can ask questions about your code. Some important things to remember when posting in this category :slight_smile:

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 + ratings
);
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 pages() {
return this._pages;
}
}

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

const historyOfEverything = new Book(‘Bill Bryson’, ‘A Short history of Nearly’, 544);

historyOfEverything.toggleCheckOutStatus();
console.log(historyOfEverything.isCheckedOut)

historyOfEverything.addRating(4)
historyOfEverything.addRating(5)
historyOfEverything.addRating(5)

historyOfEverything.getAverageRating;

[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 + ratings
);
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 pages() {
return this._pages;
}
}

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

const historyOfEverything = new Book(‘Bill Bryson’, ‘A Short history of Nearly’, 544);

historyOfEverything.toggleCheckOutStatus();
console.log(historyOfEverything.isCheckedOut)

historyOfEverything.addRating(4)
historyOfEverything.addRating(5)
historyOfEverything.addRating(5)

historyOfEverything.getAverageRating;

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 + ratings
);
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 pages() {
return this._pages;
}
}

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

const historyOfEverything = new Book(‘Bill Bryson’, ‘A Short history of Nearly’, 544);

historyOfEverything.toggleCheckOutStatus();
console.log(historyOfEverything.isCheckedOut)

historyOfEverything.addRating(4)
historyOfEverything.addRating(5)
historyOfEverything.addRating(5)

historyOfEverything.getAverageRating;

In your toggleCheckOutStatus method,
you are trying to change the value of isCheckedOut, so you should be using = instead of !=
you can do this:

  toggleCheckOutStatus() { 
    this._isCheckedOut = !this._isCheckedOut;
  }

or, if you want to use the getters and setters:

  toggleCheckOutStatus() { 
    this.isCheckedOut = !this.isCheckedOut;
  }

In the getAverageRating method, you have a typo:
ratings should be rating

And, on the last line, if you want the result of calling the function to show up on the screen/console,
you should do:

console.log( historyOfEverything.getAverageRating() );

Notice that there is a () because you want the result of calling that function (with no arguments).

Next time, please use the </> button and paste your code between the ``` and ``` so that your code keeps its formatting,
to make the code easier to read.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.