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

Tell us what’s happening: I am not quite getting this step, I keep getting errors. Please help.

textContent sets the text of a node and allows you to set or retrieve the text content of an HTML element.

<div id="example">This is some text content</div>
const element = document.getElementById('example');
console.log(element.textContent); // Output: This is some text content

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.

Your code so far

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

Your browser information:

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

Challenge Information:

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

Also, how would I check if it’s truthy or not? I know that if you put it in an if statement you can check, but how would I check through the ternary operator? Does it work like in the if statement where you just put the variable? Or do I have to put currentTitle == true

Mod Edit: Solution Removed

6 Likes

Thank You for this post. I was really struggling with the “truthy” part as well. I had it so close, I just swapped the values around the “=” sign. So much information being thrown at us in this course. Been learing a lot though. Keep learning,

Tom

2 Likes

every 3 to 5 steps there will be an instruction that make me question my literacy and general understanding of English

7 Likes

This 100%.

I spent an hour on this and when I finally found the answer, I was nowhere close. I went back and read the instructions and the instructions still don’t make sense to me. Seeing the solution, I understand how it works, but I still don’t understand the original instructions that were provided.

2 Likes

Thanks so much for this solution, I’ve been bashing my head against it for hours. I still don’t know how that’s the solution, but heck, I’ll take it