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

Tell us what’s happening:

I get the message, " You should use the ternary operator to set the textContent property of playingSong to currentTitle or ""."

Your code so far

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

I’ve also tried so many combinations of potential ternary statements (after reading forum posts, etc), that I can’t remember how many I’ve tried, or what code I first had when I started. I realize the two lines no longer match now. The error message never changes no matter what code I type.


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; 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 64

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 (').

Let’s review the instructions:

“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.”

Notice what property you are being asked to set here. If I asked you to set the variable a to a value, then which side of the equals sign would you put it on. That’s the same side that the property playingSong.textContent should be on as well.

“…use a ternary operator to check if currentArtist is truthy. If so, set songArtist.textContent to currentArtist. Otherwise, set it to empty string.”

Similarly, you are being asked to set the property songArtist.textContent to a value, so which side of the equals sign should it be on?

Once you get these two issues figured out then you can concentrate on figuring out the value you want to set for each of them using the ternary operator for each one. Just to be clear, you should only add two lines of new code. One to set the playingSong.textContent property and one to set the songArtist.textContent property. And there can only be one equals sign on each line.

Thank you. It seems that default text that instructs the poster to paste their code below the “Post your code here” should mention this in that area.

This helped. Thank you!

I am also stuck on this same step. Your comments above have helped some but I am still struggling. Below is my code so far. I am wondering if I am not checking if things are truthy correctly.

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

There are a couple of mistakes to fix here. First is the syntax of the ternary operator. It should be something like

resultVariable = ifIAmTrue ? useThis : notThis;

The second part to change is the order of the data in the statement. Where I have “resultVariable” above, you will want to specify the property (.textContent) of the variables for each line.

Thanks @troymcguire, I think part of where I am lost. the instructions say to check if currentTitle evaluates to a truthy value. What am I checking it against to determine if its a truthy or falsey?

In many cases, the text of the lessons on this site are written in very awkward ways, and/or are sometimes out of context for the lesson. This particular exercise felt very out of place to me, and has very little to do with string and array manipulation. For me, this site best serves as inspiration to research topics on MDN and w3schools where explanations and examples can be found.