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

Tell us what’s happening:

I already solved this challenge but I’m just wondering why my previous code didn’t work, removing the brackets around the condition solved the issue, but I want to know why is that the case? Aren’t you supposed to put them anyways?

Your code so far

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

/* file: styles.css */

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

  playingSong.textContent = (currentTitle) ? currentTitle : "";
  songArtist.textContent = (currentArtist) ? 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/129.0.0.0 Safari/537.36

Challenge Information:

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

it may be that the test was not expecting the parenthesis.
Normally you don’t need the parenthesis to be placed around a single variable.

so if for example it was an (x > y) condition, the parentheses aren’t optional right?
Just in this case of a boolean condition?

yes you will need the parenthesis if you have more than one term on the left of the question mark

edit: actually you may not need them for the simple comparison. It all depends on the operator precedence.

1 Like