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

Tell us what’s happening:

I don’t what is required of me in this step…almost everything I did so far is new and does not stick because it is mind boggling. ChatGPT is also clueless

Your code so far

const deleteSong = (id) => {
   userData.songs = userData.songs.filter(song);
};
<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

const deleteSong = (id) => {
   userData.songs = userData.songs.filter(song);
};


// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36

Challenge Information:

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

A call back inside the fiiter method is needed. An implicit return is what it is asking for this wont have curly brackets. It might be a good idea here to stop and read up on the subject of a call back function with a implicit return. Good luck

1 Like

This is typical. GPT doesn’t know anything and just guesses statistically likely combinations of words.


This is the key part of the instructions

Use the filter() method on userData?.songs. Pass in song as the parameter of the arrow function callback and use implicit return to check if song.id is strictly not equal to id. Assign all of that to the userData.songs.

Specifically

Use the filter() method on userData?.songs.

You aren’t quite doing this.

Pass in song as the parameter of the arrow function callback and use implicit return to check if song.id is strictly not equal to id.

You are passing in song, but have no arrow function.

Assign all of that to the userData.songs.

This part is good.

Word of advice, you shouldn’t trust ChatGPT. Especially if you don’t know what you are doing. It will always tell you what you think you want to hear and sounds right; versus the actual answer to your problems.

Secondly you are close to the right track. You need to make sure you don’t call userData when it could potentially be undefined. That is why you use the null operator.

userData?.songs

Next, you need to insert an arrow callback function into the filter method. If you are unaware an arrow function generally takes this form,

(a,b, c) => expression

where all parameters are enclosed in a parentheses with an arrow pointing at the expression. More info on arrow functions can be found here.

The function you need to add goes inside of the filter method to find the song that has the id you are looking for. This type of function is called a callback function.

More info on the filter method can be found here.

Happy coding. :slight_smile:

1 Like

here is what I came up with and I still don’t succeed

const deleteSong = (id) => {
  userData.songs = userData.songs.filter(song => song.id !== id);
};

here is the code I came up with and it still says error.

const deleteSong = (id) => {
  userData.songs = userData.songs.filter(song => song.id !== id);
};

Hi @camaguncoso

You should use the filter() method on userData?.songs .

Where is the optional chaining?

Happy coding

Optional chaining? I think I mentioned that almost everything is new in this music player project… even the code I’ve been writing throughout this project has been by luck in some cases… I don’t even know what this code is: userData.songs.filter(song => song.id !== id);

Maye I should memorise things to learn faster and avoid the frustration

1 Like

I wouldn’t worry about memorization when Google exists, honestly. I Google all the time with my professional programming job

I still get an error on the code I wrote.

const deleteSong = (id) => {
   userData.songs = userData.songs.filter((song) => song.id !== id);
   
};

You don’t have the optional chaining given in the instructions.

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