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

Tell us what’s happening:

Hi, this is my first time posing here.

I’m stuck at step 70 of building a music app . I’ve searched for help in the forum, sadly, still stuck. Here are the instructions:

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

here’s my code:
currentTitle ? playingSong.textContent = currentTitle : “”;
currentArtist ? songArtist.textContent = currentArtist : “”;

Also tried:
(currentTitle == true) ? playingSong.t…

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

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


// User Editable Region

Your browser information:

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

Challenge Information:

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

1 Like

hello and welcome to fcc forum :slight_smile:

  • wrong syntax

ternary operator structure looks like this: condition ? when true : when false

here you are supposed to use that for “var.textContent”

  • hints: songArtist.textContent=useTernaryHere

happy coding :slight_smile:

4 Likes

I tried the syntax and hints in the previous posts in these 2 ways, but both are not accepted:

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

What am I doing wrong here? I think I am following the correct syntax for a ternary operator

Couple things here, first, when you use one equal sign “=” it is the assignment operator, you are attempting to assign the value true to the variable currentTitle. The comparison operators are “==” or “===” (more info on the difference here).

However, you don’t want to make that comparison in the first place. currentTitle is a string, and thus will never equal true, which is a boolean. It can however be truthy if the string is non empty. You had the comparison part correct in your two lines above this.

3 Likes

Many thanks for your explanation on ‘=’ vs ‘==’ and ‘===’ ! That is information I will not only use for this challenge.

I got the code to work now, by checking the condition on truthy-ness without any brackets. I did not even know that was possible.

2 Likes

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