Getting audio players to play their respective streams out of their element

The playAudio() function needs to have another parameter called button, so that we can then use that button.

var src = button.getAttribute("src");

I agree with you, I was just trying to do it the other way also. And again, I like trying to figure things out. The more you do, the more you know how to do. If I donā€™t know how to do something, I want to learn and know how it would be done.

You pasted in the code, but you havenā€™t yet followed the instructions from post #21

When you add that button as parameter to the playAudio() function, you will also need to update all other parts of the code where you use playAudio

var src = button.getAttribute("src");(button);

The parameters of a function is an idea that need to learn more about.

When you declare a function, the names inside of the parenthesis are function parameters (if there are any at all), and the code that appears inside of the curly braces are called the body of the function, or the function body.

1 Like

button();

Later on when you execute a function, the terms that you place inside of the parenthesis are called the arguments. Those arguments are passed to the function and are received by the function as the named parameters of that function.

1 Like

Some useful information introducing you to functions and the terminology thatā€™s used with them, is found at this Introduction to Functions in JavaScript page.

1 Like

You said to add this to it:
(button)

var src = button.getAttribute("src");

How?

The playAudio() function needs to have another parameter called button, so that we can then use that button.

I said:

You need to identify what function parameters are, because that is the place where button goes. Itā€™s time for you to learn about function parameters.

   function playAudio(player) {
     var src = button.getAttribute("src");
     player.volume = 1.0;
     player.play();
button();
   }

This:

(button)

Good?

   function playAudio(player, button) {
     var src = button.getAttribute("src");
     player.volume = 1.0;
     player.play();
   }

function parameters
( )

In that code you have function which starts a function declaration.
After the word function is the function name.
After the function name inside of the parenthesis are the function parameters
After the function parameters is the opening brace
Between the opening brace and its matching closing brace, is the body of the function.

function functionName(parameters) {
    // function body
}
1 Like

This is right then?

   function playAudio(player, button) {
     var src = button.getAttribute("src");
     player.volume = 1.0;
     player.play();
   }

Good one.

Other places in the code where you use playAudio need to be updated too, so that a second argument is given to the function.

Here:

     } else {
       showPauseButton(button);
       playAudio(player, button);
     }
   }