Two versions of a playButton Binding Audio With a grid link structure


Does the code work?


ReferenceError: isPlaying is not defined
[Learn More]


You failed to follow these instructions.

Do that.


  var pause = button.querySelector(".pause");
     player.volume = 1.0;
     if (isActive() && isPlaying()) {


You have isPlaying() there which is wrong. Fix it.



Good, the play button still works.

We can now replace that return true statement, with code that checks if the button is active, which is:

return button.classList.contains("active");

That won't work though until you give isActive the button, so change isActive() to isActive(button) and all is good.


   var pause = button.querySelector(".pause");
     player.volume = 1.0;
     if  (isActive(button)() && player.paused) {


It looks like a mistake occurred when you attempted to follow one of those instructions.


What was the mistake?


Here's what I said:


   function isActive(button) {
   return button.classList.contains("active");


You still haven't changed isActive() to isActive(button) so do that.


Which one?

[ function isActive(button) {

if (isActive() && player.paused) {



What you show there is the function declaration which shows that it receives one parameter called button.
That is not what I'm talking about.

I am talking about the if statement that currently has isActive()

That calls the isActive function with no arguments. You need to call the isActive function with an argument of button.


Good, that looks like it works as desired now.




Change playing/triggered to active, or leave as is?

    function isPlaying() {
        return player.paused === false;
    function toggle() {
        if (isPlaying())



Are you wanting to work on the other code there now?


Please edit your post before hitting Reply.

When you go back to edit it afterwards, no notifications are sent out about the changes that you made after doing the reply.

Exposure from the depths of large topics