Learn Basic String and Array Methods by Building a Music Player - Step 40

Tell us what’s happening:

My issue here is not passing the challenge, but rather the note included in the instruction:

Namely, “[y]ou should not use the optional chaining operator ?. in this step because userData.currentSong will not be null or undefined at this point.”

But what if the user has not yet selected a song? Wouldn’t userData.currentSong be null in that case?

What am I missing here?

Thank you for your help!

Challenge Information:

Learn Basic String and Array Methods by Building a Music Player - Step 40

hello and welcome to fcc forum :slight_smile:

did you also take a note on this instruction?

Assign song to the currentSong property on the userData object

as “song” is already “available” in this scope, you can assign it to userData prop

or you are asking something different? happy coding :slight_smile:

Thank you for your reply!

I think I mean something different.

It is exactly in this assigning you are pointing to , namely userData.currentSong = song;, where I feel like I’m missing something.

My understanding is that the expression userData.currentSong accesses the currentSong property of the userData object I have declared earlier in the code like so:

let userData = {
  songs: [...allSongs],
  currentSong: null,
  songCurrentTime: 0,
};

If the user has just begun their session and selects a song, userData.currentSong will be assigned the current song for the first time at which point the value is still null, is it not? I see that it will have a value (other than null) after this step, but not before (and during) the assigning itself, right?

Thanks again!

you are assigning song to an existing property, so you don’t need to worry about the previous value of userData.currentSong, you are assinging to it
I don’t even understand why the optional chaining note is there, it’s quite confusing