Using the ternary operator syntax, i had tried currentTitle ? , as a condition before assignment of the .textcontent. I am not sure if the condition syntax suites to work for checking for truthy, but I couldn’t pass the code with it. however, had used the syntax successfully using the if statement method in tasks other than this.
okay, I took another look and here’s what I found:
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.
so the first part is use a ternary which you have done to check currentTitle
the 2nd part 'set playingSong.textContent` to means that we should have playingSong.textContent on the left side of the equal sign.
And on the right side we can have the ternary to choose between the variable and the empty string.
So something like this:
let myVariable = isItTrue ? "yes" : "no";
This code would set myVariable to yes or no depending on the check of isItTrue
I’m a bit confused, while though i understand the syntax used in your description, am not sure how to apply it in the case of the task objective. Since i had used currentTitle as a condition followed by the ternary operator ? , and the rest of the syntax, does it mean i will use a second ternary operator ? sign to check again if currentTitle = playingSong.textContent?
updated code below:
currentTitle ? playingSong.textContent = currentTitle : currentTitle =“”;
current Artist ? songArtist.textContent = currentArtist : currentArtist =“”;
Use a ternary operator to check if isItTrue evaluates to a truthy value. If it does, set myVariable to "yes". Otherwise, set it to "no".
What the instruction asked is:
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.
Thank you very much, i tried to put that to work but still can’t pass my code.
updated code below:
currentTitle ? playingSong.textContent = currentTitle : playingSong.textContent =“”;
currentArtist ? songArtist.textContent = currentArtist : songArtist.textContent =“”;