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

Tell us what’s happening:

const sortSongs = () => {
userData?.songs.sort()

};

renderSongs(userData?.songs);

Your code so far

WARNING

The challenge seed code and/or your solution exceeded the maximum length we can port over from the challenge.

You will need to take an additional step here so the code you wrote presents in an easy to read format.

Please copy/paste all the editor code showing in the challenge from where you just linked.

Replace these two sentences with your copied code.
Please leave the ``` line above and the ``` line below,
because they allow your code to properly format in the post.

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0

Challenge Information:

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

what questions do you have for this step?

i dont know what to do i tried everything i looked everwhere and cant find the solution

you need to start creating the callback that goes as argument to sort, for now you have the instructions on the function parameters and to have an empty function body

To sort the songs in alphabetical order by title, you will need to pass in a compare callback function into your sort() method.

function userData?.songs.sort(a, b) {
  return a - b;
}
function compare.userData?.songs.(a, b) {
  return a - b;
}

that’s a lot of syntax errors, delete everything you have added, everything you add needs to go inside the parenthesis of sort(), inside those parenthesis start writing your callback function, use arrow function, write the parameters and leave the body empty

thats just examples of what i tried so far… theres more but i didnt feel like sending a novel. i just dont understand what thhat means and the resources to figure it out are vague and very difficult to understand

userData?.songs.sort((a, b ) => {
if (a.song < b.song) {
return -1;
}
})

empty function! remove everything between {}

thank you i was so frustrated i almost gave up

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