Shuffle Error ? Build a Library


#1

I think i F up the program , would you help me out here

Code :

       class CD extends Media {
  constructor(title,artist,trackCount) {
    super(title)
    this._artist = artist
    this._trackCount = [] 
  }
  
  get artist() {
    return this._artist
  }
  
  get trackCount() {
		return this._trackCount
  }
  
  addTrack(trac) {
    this._trackCount.push(trac)
  }

  shuffle() {
		const a = this._trackCount.length
    for (let i = 0; i < a ; i++) {
      const j = Math.floor(Math.random() * (i + 1));
        [a[i], a[j]] = [a[j], a[i]];
    }
    }
  }

const test = new CD('INVALID' , 'INVALID' , 2)
console.log('                                       ')
test.addTrack(['Cant Hold US' , 'Cukup Tau'])
console.log(test.trackCount)
console.log(test.shuffle())

Error :
UNDEFINED

Yo, if you could please help me out as quick as possible thanks!


#2

shuffle doesn’t return anything, so it returns undefined.

so by calling console.log() when you call shuffle, you log this returned result to the console. Just get rid of console.log when calling shuffle to not log returned result


#3

Done,then what am i supposed to do next?


#4

i would first fix your indent before moving on. The indent looks like a mess.


#5

Just like my life :cry:


#6

well, indent is fixable so then your life should be fixable as well, making the same analogy.


#7

ayeee JK man,loving life


#8

impossible, programmers do not have enjoyable life.

spoiler: just kidding


#9

Nice, what am i supposed to do know


#10

simple: