Classes: Build a Library, Shuffle Method

This is step 25:
https://www.codecademy.com/courses/introduction-to-javascript/projects/build-a-library

My array is not shuffling. What is wrong with my shuffle method?

class CD extends Media {
constructor(title, artist, length, songTitle){
super(title)
this._artist = artist;
this._length = length;
this._songTitle = ;
}

get artist () {
return this._artist;
}

get length () {
return this._length;
}

get songTitle () {
return this._songTitle;
}

addSongTitle (newSong) {
return this.songTitle.push(newSong);
}

shuffle () {
let i = this._songTitle.length

while (--i < 0) {
 let randomNum = Math.floor(Math.random() * (i+1))
 let	randomNumIndex = this._songTitle[randomNum] 
	this._songTitle[randomNum] = this._songTitle[i]
  this._songTitle[i] = randomNumIndex;
}  
return  this.songTitle;

}
};

const ■■■■ = new CD(‘■■■■’, ‘Kendrick Lamar’, 40);
■■■■.addSongTitle(‘DNA’);
■■■■.addSongTitle(‘Blood’);
■■■■.addSongTitle(‘Loyalty’);
■■■■.addSongTitle(‘LOVE’);
■■■■.addSongTitle(‘Mother’);

console.log(■■■■.songTitle);

console.log(■■■■.shuffle());

Here is my code that worked :slight_smile:

// CD Class
class CD extends Media {
  constructor(artist, title) {
    super(title);
    this._artist = artist;
    this._songs = [];
  }
  get artist() {
    return this._artist;
  }
  get songs() {
    return this._songs;
  }
  addSong(newSong) {
    return this.songs.push(newSong);
  }
  shuffle() {
    return this.songs[Math.floor(Math.random()*this.songs.length)];
  }
}

// Test of Shuffle
const melodrama = new CD('Lorde', 'Melodrama');
melodrama.addSong('Green Light');
melodrama.addSong('Sober');
melodrama.addSong('Homemade Dynamite');
console.log(melodrama.shuffle());
1 Like