0

I have a question about line 5 of this little Javascript program. With the parentheses/parameters on line 5, audioNumber is inside/next to the inner parentheses because audioNumber is a parameter of .indexOf. Whereas the number 1 on this line is a parameter of .splice so it is inside the outer parentheses. Is this a correct understanding of why audioNumber and 1 are where they are on line 5?

function playAudio(audioNumber) {
  var audio = document.getElementById('sound' + audioNumber);
  audio.play();
  var nonPlaying = [1, 2, 3, 4, 5, 6, 7];
  nonPlaying.splice(notPlaying.indexOf(audioNumber), 1); // line 5
  nonPlaying.forEach(function(id) {
    document.getElementById('sound' + id).pause();
    document.getElementById('sound' + id).currentTime = 0;
  });
};
Cœur
  • 37,241
  • 25
  • 195
  • 267

2 Answers2

0

Yes, It's right! but one slight difference these are arguments not parameters.

Shahzaib Shahid
  • 1,341
  • 1
  • 8
  • 6
0

The splice method can be used with 2 parameters: the start index and the number of elements to delete:

array.splice(start, deleteCount)

The 'audioNumber' is the parameter of the indexOf method:

notPlaying.indexOf(audioNumber)  

...the result returned by the indexOf method is the first parameter (the 'start' parameter) in the splice method whereas the value '1' is the second parameter in the splice method (the 'deleteCount' parameter).