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

Tell us what’s happening: It keeps saying “You should use document.getElementById() and pass in song-${userData?.currentSong?.id} .”

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.

const song = document.getElementById(song-${userData?.currentSong?.id});
const songToHighlight = song-${userData?.currentSong?.id};

Your browser information:

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

Challenge Information:

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

document.getElementById expects a text string (enclosed by ``, ’ ’ , or " "). Since we are also using a variable directly inside the text string (with the ${variable here}), we need to use a string literal using the backticks (`).

var song = document.getElementById(`song-${userData?.currentSong?.id}`);
const songToHighlight = `song-${userData?.currentSong?.id}`;

This is my current code, it keep saying the same thing

My code contains the backstick

@megacartenterprises Did you figure it out? The code you shared does not contain backticks.
The first line should be: var song=document.getElementById(song-${userData?.currentSong?.id});

second line should be similar.

I just realized that the forum removes the backticks in code and that you should put sample code in triple backticks and end with triple backticks.
```

song=document.getElementById(`song-${userData?.currentSong?.id}`);

```
Or you can escape the backtick with \`.
so you get the output in the forum:
var song = document.getElementById(`song-${userData?.currentSong?.id}` );

But it actually looks like:
var song = document.getElementById(\`song-${userData?.currentSong?.id}\`);

Now to your question:
Your problem isn’t with the backticks. Have you used every instruction given to you in this step? The point of this step is to query the music player to find out which song is currently playing (the id of said song) and then to highlight it. So how do we query the page?

It should be one line of code.

This part of your code is correct

document.getElementById(`song-${userData?.currentSong?.id}`);

and this part

const songToHighlight =

Now combine the two into one line of code.


I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

1 Like