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

Hello

I found the solution in another post but I can’t understand why my solution is wrong.

currentTitle ? textContent = currentTitle : "";
// currentTitle (truthy?) ? (then) textContent = currentTitle : (else) "";

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.

I think you meant step 64, right?

The ternary operator is basically a short cut for using an if/else construct. Instead of doing:

if (meows) {
  animal = "cat";
}
else {
  animal = "dog";
}

you can do:

animal = meows ? "cat" : "dog";

Notice that all of the logic is on the right side of the equals sign and the variable you want to set is on the left side of the equals sign. In your solution, is the logic on the correct side of the equals sign? And you are supposed to be setting the value for playingSong.textContent but I don’t see that in your solution at all. Which side of the equals sign should you add it to?

1 Like

Thank you! Your explanation was very helpful. Now I understand much better how it works.

Yeah, it’s step 64.

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