Build a library

i have declare a subclass named CD for more challenge but when i want to call a shuffle method from my class i get this thing in the console :
[Function: shuffle]
this is my code :

class Media {
    this._title = title;
    this._isCheckedOut = false
    this._ratings = []
  get title(){
    return this._title
  get isCheckedOut() {
    return this._isCheckedOut
  set isChekedOut (newisCheckedOut) {
    return this._isCheckedOut = newisCheckedOut

  get ratings() {
    return this._ratings
  toggleCheckedOutStatus (){
 this._isCheckedOut = !this._isCheckedOut
  get average () {
    return this.getAverageRating()
  getAverageRating (){
    let ratingsSum = this._ratings.reduce(( currentSum, rating) =>  currentSum + rating)
    return ratingsSum / this._ratings.length
  addRating(rate) {

class CD extends Media {
  constructor(title) {
    this._songs = []
  get songs() {
    return this._songs
  addSongs(song) {
  get shuffle()  {
    return this.shuffle()
  shuffle() {
    songNum = Math.floor(Math.random() * this._songs.length)
     return this._songs[songNum]

const rap = new CD ('Rap')
rap.addSongs('Inti 7ayala')
rap.addSongs('LOSE YOURSELF')


Getters and setters are used for properties. Not sure why you have a getter for the shuffle method. Your code has 2 definitions for shuffle, so the second one overwrites the first. When you try to log rap.shuffle you see what you get. If you want to log the return value of a method, you have to call the method: console.log(rap.shuffle());. You could remove the getter, and call the method, or you’ll have to employ the getter as you have for the other properties that have a getter by changing the name of the actual shuffle method. By convention, I suppose you could rename it _shuffle, and then return the result of calling it from your getter (return this._shuffle();), but once again, it’s odd to use a getter for a method.

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