Music Player Step 83

Use an if statement to check if nextSongExists exists, then call the playNextSong() function in the if block. This will automatically play the next song when the current song ends.

My code so far:

if (nextSongExists !== undefined) {

My error is :

You should create an if statement with the condition nextSongExists.

What am I missing?

So a handy shortcut in JavaScript (and most languages) is you can pass just the variable into the if statement to check for its existence.

For instance, if I wanted to check if theGallonOfMilkInMyFridge is there or not, I can just say if(theGallonOfMilkInMyFridge). It doesn’t matter if it’s almost empty, half full, or unopened since I was only asking if it was there. If the kids drank it and it’s gone (but you know kids, it’s empty, or 0), or I used it and threw out the carton (null), or if I actually never buy milk (undefined), it will come back false.

1 Like

when you asking questions, could you please also share those step/exercise url too? thanks and happy coding :slight_smile: