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

Tell us what’s happening:

Use a ternary operator to check if currentTitle is truthy. If so, implicitly return currentTitle otherwise implicitly return an empty string. Assign this result to playingSong.textContent.

Then, use a ternary operator to check if currentArtist is truthy. If so, implicitly return currentArtist otherwise implicitly return an empty string. Assign this result to songArtist.textContent.

Your code so far

playingSong = currentTitle.textContent == true ? currentTitle : “”;
playingSong = currentArtist.textContent == true ? currentArtist : “”;

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 Edg/120.0.0.0

Challenge Information:

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

Can you be a bit more specific about why the instructions or error message is confusing?

You aren’t using truthiness here.

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

This is the error:

Sorry, your code does not pass. Try again.

You should chain the textContent property to playingSong.

You aren’t using truthiness here.

I guess I don’t understand truthiness, I’m checking if currentTitle is true, how can I check truthiness?

“truthiness” means that a value acts like a literal true without an explicit comparison.

using “if () {}”? But how would I use if AND a ternary operator?

You don’t need to use if.

This is an implicit comparison to true. Ditch it. Use the value itself because values will either behave as if they are true or false without a comparison or explicit casting.

so to check the truthiness of currentTitle I have to compare it to itself?
like:

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

No, make no comparison at all. Use the value itself as if it was a weak comparison to true

1 Like

Thanks I got it. I guess it makes sense now e.e

1 Like

Its a trippy concept, for sure

Mod Edit SOLUTION REMOVED

that is the solution.!

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

1 Like

can you explain the objective of making this comparison? I don’t understand…

What might happen without the comparison? If we don’t have a currentTitle or currentArtist what would happen?

1 Like

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