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

Tell us what’s happening:

My ternary operators are not working. What am I doing wrong?

currentSong ? currentTitle = playingSong.textContent : currentTitle = “”;
currentArtist ? currentArtist = songArtist.textContent : currentArtist = “”;

Your code so far

<!-- file: index.html -->

/* file: styles.css */

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

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

// 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/124.0.0.0 Safari/537.36 Edg/124.0.0.0

Challenge Information:

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

please look at the example again:

const example = condition ? "I'm true" : "I'm false";

You need to put the variable you are changing on the left of the equal sign.
So when they said:

set playingSong.textContent

They meant that this should go on the left of the equals.

Now we need to go back and read the instructions again:

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.

What is the thing we are checking according to this sentence?
We are checking if currentTitle is a truthy.
So we must write this variable name instead of the condition (in the location of the condition) to the left of the question mark.

And after that, we place the values we want when the condition evaluates to true (currentTitle) and to false (empty string).

Now that I’ve broken this part of the step down, please try again.
(Try to consider what is the condition, what is the variable that is changing, and what is the value in the case of true or false)

2 Likes

const currentTitle = (currentTitle) ? playingSong.textContent = currentTitle : “”;
const currentArtist = (currentArtist) ? songArtist.textContent = currentArtist : “”;

This is my new code. What am I doing wrong? Thank you for helping!

You have too many equal signs. Look at the example again, follow that syntax and read @hbar1st comment.

What variable are you trying to set?

There’s no brackets around the condition in the example as well.

1 Like

const playingSong.textContent = currentTitle ? currentTitle : “”;
const songArtist.textContent = currentArtist? currentArtist : “”;

like this? I am completely lost. Thank you!

The period gets a red underline.

why do you think you need the const in the line?
const is used to declare variables right?
Are either playingSong.textContent or songArtist.textContent variables that need to be declared here?

edit: i think you put the const here because of the example? The example is just an example and since you are setting a variable only and not also declaring one, you don’t need the const.

If you’re unsure why, please ask us.

Got it! Thank you for helping everyone!

2 Likes

I must say this step was a bit challenging based on how the ask is written out. I understand that it is meant to challenge the learner but this flat out confused me. I had to review 3 of these posts asking for help to get an idea of what I was doing wrong.

1 Like

I wonder if the wording is intentially done like this. Because, honestly, they could do such a betterjob explaining many problems.

1 Like

If you know how to reword it better, you can suggest that on GitHub.