This is definitely a beginner problem, but I can’t figure it out or find an answer anywhere, so I’m hoping someone here can tell me what I’m doing wrong without too much bother. I'm making a call to an API, getting a series of ID numbers corresponding to categories back that I'm putting into an array. I want to then shuffle the numbers in that array so I can use the ID numbers in a random order easily later on. When I run this code I get an error that the return statement at the end is an illegal return statement. If I run it without the stuff with the counter and my attempt at shuffling, there's no error.
async function getCategoryIds() {
let idArray = [];
let fullCatInfoArray = [];
let response = await axios.get('API URL');
for (let cats of response.data) {
idArray.push(cats.id);
}
let counter = idArray.length;
while (counter > 0) {
let index = Math.floor(Math.random() * counter);
counter--;
let temp = idArray[counter];
idArray[counter] = idArray[index];
idArray[index] = temp;
}
return idArray;
}