Need help on Step 70 JavaScript

Use a ternary operator to check if currentTitle evaluates to a truthy value. If it does, set playingSong.textContent to currentTitle. Otherwise, set it to an empty string.

Then below that, use a ternary operator to check if currentArtist is truthy. If so, set songArtist.textContent to currentArtist. Otherwise, set it to empty string.

const playingSong = document.getElementById("player-song-title");
  const songArtist = document.getElementById("player-song-artist");
  const currentTitle = userData?.currentSong?.title;
  const currentArtist = userData?.currentSong?.artist;

  currentTitle ? currentTitle = playingSong.textContent : "";
  currentArtist ? currentArtist = songArtist.textContent : "";

Can someone please help me about this code Iā€™m very stuck here

This can be a bit confusing, but I will try to explain it with a simpler example.
Here i will use a ternary operator to set the textContent of user to firstName, if firstName is truthy, or an empty string, if it is falsey.

user.textContent = firstName ? firstName : "";
2 Likes

ohhh so that how its done thank you very muchhh :slight_smile:

1 Like

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