Why is this Function not running properly?

Why is this Function not running properly?
0

#1

/*Create a function called indexFinder that will loop over an array and
return a new array of the indexes of the contents e.g. [243, 123, 4, 12] would return [0,1,2,3].
Create a new variable called ‘indexes’ and set it to contain the indexes of randomNumbers.

( I keep getting an error that indexes is not defined)*/

let randomNumbers = [1, 3453, 34, 456, 32, 3, 2, 0];


function indexFinder(arr) {
  var indexes = [];
  for (i=0; i<arr.length; i++) {
    indexes.push(i);
    }
    return indexes;
}

#2

What code are you using to call the function indexFinder? I do not see a sample call.

If I make a call to your indexFinder function and use randomNumbers as the argument, your function correctly returns an array of indexes.

indexFinder(randomNumbers); //  [ 0, 1, 2, 3, 4, 5, 6, 7 ]

#3

The program I’m working through automatically runs the function when you save it.


#4

If that is the case, why do you even need to create the array called randomNumbers in your code. Is the function called with randomNumbers as the argument or another array?

Without seeing how the function is called, all I can tell you is that your function does return an array of indexes if it is called with an array for the function argument.


#5

The commented out section at the top pf my post is all that is provided in the problem. The declared randomNumbers array is already initialized in the question. I didn’t create it.


#6

I think it may be a glitch in the testing program.


#7

Then I think they want you to reference the global variable randomNumbers inside the function instead of using a parameter (i.e. arr) to pass an array in. Try that instead and see what happens.


#8

Ok, I’ll just do that. Thank you for the help!