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

Tell us what’s happening:

can any one help me i try with also constant but still the same

Your code so far

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

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

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

// User Editable Region
/* file: styles.css */

Your browser information:

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

Challenge Information:

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

Hi there,

The syntax of a ternary operator is like this:

variable_name = condition ? value_if_true : value_if_false

What it does is:

check if condition is truthy. If so, set variable_name to value_if_true. Otherwise, set it to value_if_false.

1 Like

currentTitle = currentTitle ? playingSong.textContent: “”
i try this also but still give me error

The syntax of a ternary operator is like this:

variable_name = condition ? value_if_true : value_if_false

What it does is:

check if condition is truthy. If so, set variable_name to value_if_true. Otherwise, set it to value_if_false.

What the instruction asked is:

check if currentTitle is truthy. If so, set playingSong.textContent to currentTitle. Otherwise, set it to an empty string.

So,
the condition here is currentTitle
the variable_name here is playingSong.textContent

and so on

1 Like

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

The instruction said:

check if currentTitle is truthy. If so, set playingSong.textContent to currentTitle

So, value_if_true here is currentTitle

currentTitle is Value_if_true and condition

1 Like

The key to the solution is not on how the ternary operator works. Read carefully, the form of the question can be confusing. Here you are assigning values to the ‘textContent’ attribute

mod edit: solution code removed

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.

mod edit: code removed

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.