Build a Library Project

Hi everyone,

I’m working on the project Build a Library link : https://www.codecademy.com/courses/introduction-to-javascript/projects/build-a-library.

I’m stuck at Step 16. I dont know why it gives me ReferenceError. There is something wrong with my method toggleCheckOutStatus() or my Book class, I can’t figure it out.

Can you help me please?
here is my code :

Hi there.

In your class definition, you have a method toggleCheckOutStatus. Your ReferenceError is coming from the variable isCheckedOut not existing at that point in the code…

Can you see how you’ve incorrectly used isCheckedOut here? :slight_smile: (I’ll give you a hint… you’re using a class method…)

1 Like

Dear [thepitycoder] ,

Thank you for your help, I understand what you want to say if I change

isCheckedOut(true) to return this._isCheckedOut=true;
or

isCheckedOut(false) to return this._isCheckedOut=false;

My code will work.

The question is more like : Why I cant use here the set method that we created before?

(set isCheckedOut(value){
    this._isCheckedOut=value;
  }

You see what wanted to do ? isCheckedOut(true) if I put isCheckedOut(true) it should return me this._isCheckedOut=true;

Yes, I understood that is what you wanted to do.

I’ll use the example function you gave; can you see what you’re doing here to access a class attribute

set isCheckedOut(value){
    this._isCheckedOut=value;
  }

which you are not doing here, when you’re attempting to access a class method

  toggleCheckOutStatus(){
        if (this.isCheckedOut === false){
      isCheckedOut(true);
    } else if (this.isCheckedOut === true){
      isCheckedOut(false);
    }
  }

I did’t understand what you wanted to say(my english is not great) I just changed my code :

toggleCheckOutStatus(){
    if (this.isCheckedOut === false){
    return this.isCheckedOut=true;
    } else if (this.isCheckedOut === true){
     return this.isCheckedOut=false;
    }
  }
1 Like

As you are helping me (thank you by the way) I have another question at Step 25 :

My full code is here

So I created a new sub classe CD as you can see :

class CD extends Media {
  constructor(title,artist,year,songs){
    super(title);
    this._artist = artist;
    this._year = year; 
    this._songs=[];
    }
  get artiste(){
    return this._artist;
    }
  get year(){
    return this._year;
  }
  get songs(){
    return this._songs;
  }
  //Fisher–Yates Shuffle
  shuffle(songs) {
    let randomSongs = songs;
    let i = this.randomSongs.length, t, j;   
    while(--i > 0){      
      j = Math.floor(Math.random() * (i+1));
      t = randomSongs[j];
      randomSongs[j] = randomSongs[i];
      randomSongs[i] = t
    }
    return randomSongs;
  }

When I try to create a new object theBeatles with an array of songs its doesn’t show me the array of songs

const theBeatles = new CD ('A Hard Day\'s Night ','The Beatles', 1964, ['A Hard Day\'s Night','Tell Me Why','I\'ll Cry Instead','Can\'t Buy Me Love','And I Love Her','If I Fell', 'I Should Have Known Better'])

console.log(theBeatles)

When I console log my created object theBeatles it doesn’t show me songs.
I don’t understand why cn you help me please ?

Thank you in advance.

1 Like

Sorry, I’m not able to explain the content here in any other language. :frowning:

What I was trying to get you to do is realise that, because isCheckedOut() is a method belonging to your Media class you need to do this:

   toggleCheckOutStatus(){
        if (this.isCheckedOut === false){
      this.isCheckedOut(true);
    } else if (this.isCheckedOut === true){
      thi.isCheckedOut(false);
    }
  }

You were just missing the this keyword.

In your constructor, are you giving this._songs a meaningful value? Hint: No, you’re creating it as a blank array.

1 Like

Many thanks thepitycoder.

Have a nice day

1 Like