Im so confuse with the error message

Tell us what’s happening:
I already checklist all other issues, but these two still give me wrong.
why false condition gives 3 as a return?
I got error like this:

// running tests
getIndexToIns([2, 5, 10], 15)
should return 3
getIndexToIns([], 1)
should return 0
// tests completed

Your code so far

function getIndexToIns(arr, num) {
arr = arr.sort(function(a, b){
  return a - b;
for (let i = 0; i < arr.length; i++){
  if (arr[i] >= num){
    return i;
return num;

getIndexToIns([40, 60], 50);

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36.

Challenge: Where do I Belong

Link to the challenge:

Hi, your problem is this line: return num.

That means - for getIndexToIns([2, 5, 10], 15), you’re returning 15 when it should return 3.

In the cases that fail, the if condition in your loop never runs, because the num given is always greater than all array values. So, try to figure out what you need to return instead in those cases.

Thank you, I figure out what should do after read your advice.