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

Tell us what’s happening:

Hello, I’ve been struggling with this one for a while. Here is my code:

The instructions are asking to set the values of currentTitle and currentArtist if they are truthy. I’ve set currentTitle/currentArtist equal to the results of the ternary operator,but receive an error/tip that says:

" You should use the ternary operator to set the textContent property of playingSong to currentTitle or "" . " Any help would be appreciated.

Your code so far

/* file: script.js */
// User Editable Region

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

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge Information:

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

This might be worded a bit strange, but what’s needed is modifying the playingSong.textContent and songArtist.textContent, with whatever will be returned in the ternary operation.

Hmm…I agree that your wording is a bit strange. Here is how i understand the ternary operation:

currentTitle ? playingSong.textContent : “”;
(condition) ? (return if true) : (return if false)

Is my understanding correct?

That’s correct - (condition) ? (return if true) : (return if false)

That means though, for currentTitle = currentTitle ? playingSong.textContent : "";:

  • If currentTitle is truthy, playingSong.textContent will be assigned to currentTitle.
  • If currentTitle is falsy, "" will be assigned to currentTitle.

Which is not the goal. It should be currentTitle or "" assigned to playingSong.textContent

Assignment is starting from left to right.

Assign ternary statement to textContent in both line of code.


value.textContent = condition ? value : value;
1 Like

Got it. Thank you for explaining it. The wording on the instructions really threw me off.

1 Like