'Where do I belong?' Challenge issue

Tell us what’s happening:
Hello all, I have managed to get this code to somewhat work for about half the challenges required but a lot of them return the wrong answer. What am I missing here?

Your code so far

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

console.log(getIndexToIns([40, 60], 50));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0.

Challenge: Where do I Belong

Link to the challenge:

look at the foloowing line of code you wrote:
return arr.indexOf(num);
my guess is that the function will constantly output -1 if num isn’t in the array.
look carefully at the last word ;).
and look for cases that num is bigger than every value in the array, what will you do then?

1 Like