Basic Algorithm Scripting - Where do I Belong

Below is my code, when I run this code in VS Code does give me the expected result, however I keep getting errors on freeCodeCamp console. Please help! :frowning:

  **Your code so far**
function getIndexToIns(arr, num) {
let tempElement;
for(let i = 0; i < arr.length; ){
  if(arr[i] > arr[i+1]){
    tempIndex = i+1;
    tempElement = arr[i+1];
    arr[i+1] = arr[i];
    arr[i] = tempElement;
for (let element of arr){
  if(num <= element){
    return arr.indexOf(element);
return arr.length

getIndexToIns([40, 60], 50);
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Basic Algorithm Scripting - Where do I Belong

Link to the challenge:

This is a sign that you are using your for loop wrong.

The function will return the very first time this is true.