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

Tell us what’s happening:

This is how I tried to solve the ternary question but for some reason It still not passing.
I tried many different ways but still not working

  1. currentTitle ? playingSong.textContent = currentTitle: “”
  2. const innerText = currentTitle ? playingSong.textContent = currentTitle: “”
    playingSong.textContent = innerText
  3. currentTitle !== undefined ? playingSong.textContent = currentTitle: “”
  4. currenTitle != null ? playingSong.textContent = currentTitle: “”

Your code so far

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

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

 
   const c = !currentTitle ? currentTitle: ""
      playingSong.textContent = c
    currentTitle ? playingSong.textContent = currentTitle: ""
 

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36

Challenge Information:

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

Hi there. Read the instructions carefully:

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.

You need to write first the variable with .textContent then assign it ternary expression as requested.

Put the element assignment to the left of the ternary so it gets assigned the value the ternary expression evaluates to.

const value = true ? "was true" : "was false";
console.log(value); // was true

More complete syntax example:

someElement.textContent = someValue ? someValue : "";

Thank you for all your contribution

thank you for your explaination

1 Like