I had a lot of issues getting through this step. However, I did end up getting this step answered. But I am still confused at how the answer worked. Questions listed below:
Why in the expression that gets executed when the conditional evaluates to truthy I did NOT have to explicitly call out what currentTitle should be set to and all I have to do is list currentTitle? Same goes for when you want currentTitle equal to a empty string when the conditional evaluates to falsey all I did was list “”? Code shown below, remove if not allowed. Why did this work?
Why in the function is there no return statement? Don’t we need to return what we want the currentTitle and currentArtist to be set to? Or does the above statement that I am confused on somehow setting the innerHTML of the two different html elements (coming from who knows where this is my next question) causing it to render on the player as long as the function as a whole is called?
Also the function has you grab the HTML elements with the ID of player-song-title and player-song-artist. Where are those defined? I didn’t see them in the HTML document so I am assuming its getting dynamically created somewhere in the js file but I cant seem to find it. So confused where these come from?
To see what this value currently holds, you should add a console statement like this outside of one of the functions.
console.log(userData?.currentSong?.title)
you can add that console statement on line 141 and open the console.
The console shows undefined
That makes sense because when you first load the page, there shouldn’t be a current song.
undefined is known as a falsey value in javascript
basically what this line of code is saying is if we actually have a currentTitle then go ahead and show it, otherwise, show nothing. Because we don’t want to show undefined because that wouldn’t be a pleasant experience.
The only purpose for this function is to update the text content for playingSong and songArtist. We don’t need to explicity return anything there.
If we had a function, for example that did some sort of mathematical calculations and needed that result, then it would be a good case to return something.
For example, I can have this function that calculates the area, call that function and assign that result to a const variable called area and then use that area variable throughout my program.
In this case, we are setting the textContent which is a little different from innerHTML
here is another example of working with textContent
But whenever you play a song, then the playSong function will fire, which goes through that set of code. That set of code includes calling the setPlayerDisplay function