Why is my addAt method is wrong?

Tell us what’s happening:

when i test it, it worked but in this challenge it wrong

Your code so far


function LinkedList() {
var length = 0;
var head = null;

var Node = function(element) {
  this.element = element;
  this.next = null;
};

this.size = function() {
  return length;
};

this.head = function() {
  return head;
};

this.add = function(element) {
  var node = new Node(element);
  if (head === null) {
    head = node;
  } else {
    var currentNode = head;

    while (currentNode.next) {
      currentNode = currentNode.next;
    }

    currentNode.next = node;
  }
  length++;
};

// Only change code below this line
 this.addAt = function(index, element){

  let startIndex = 0;
  let added = false;
  let node = new Node(element);
  let currentNode = head;

   if(index < 0 || index > length ) return false
     
   if(index == 0) {
     length = 0
     return head = node
   }
   
   while(!added){
    startIndex++
     if(startIndex == index ){
       let nextNode = currentNode.next;
       let result  = nextNode.next;
       nextNode.next = node;
       node.next = result;
       added = true;
     }

     currentNode = currentNode.next
   }
    length++
    return length
 }
// Only change code above this line
}
let link = new LinkedList();

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; ) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36.

Challenge: Add Elements at a Specific Index in a Linked List

Link to the challenge: