It seems to me that I am getting the correct results, but I can not pass the exercise (test)?

I have a problem on a JS freeCodeCamp exercise-test under Basic Algorithm Scripting / exercise No. 14 - “Where do I Belong?”:

In my IDE and browser console I am getting the correct results with my code, but it seems I messed something (despite correct results) as I can not pass through to the next exercise, and I do not understand what is the problem either, so please help, anyone?

My code - solution:

function getIndexToIns(arr, num) {
arr.push(num);
arr.sort(function(a, b){return a-b});
for(let tempVal in arr){
if(arr[tempVal]===num) {
num = tempVal;
};
};
return num;
};
getIndexToIns([2, 5, 10], 15);

Thank you very much in advance!

Kind regards, SexFalse

You’re returning string instead of number.

1 Like

Ooo, thank you very very much! I bow to you! Jenovs for president!:slight_smile:

Thanks one more time and I whish you all the best.