Create a Doubly Linked List(remove all)

Tell us what’s happening:
This is my code, tell me if i am doing something wrong.

Your code so far


var Node = function(data, prev) {
this.data = data;
this.prev = prev;
this.next = null;
};
var DoublyLinkedList = function() {
this.head = null;
this.tail = null;
// change code below this line
this.add=function(element){
    let node=new Node(element,null);
  if(this.head===null){
    //empty list
    this.tail=node;
    this.head=node;
  }
  else{
    this.head.prev=node;
    node.next=this.head;
    this.head=node;
  }
}

//Also remove multiple same elements present in list
this.remove=function(element){
  let count=0;
  let temp=this.head;
  while(temp!==null){
    //if  item is found
    if(temp.data===element){
      //Remove item
    //if only one item
    if(temp.prev===null && temp.next===null){
        this.tail=null;
        this.head=null;
    }
    else if(temp.next===null){
    // if item is last in list
      temp.prev.next=null;
      this.tail=temp.prev;
    }
    else if(temp.prev===null){
    //if item is first in list
      temp.next.prev=null;
      this.head=temp.next;
    }else{
    //it item is inbetween list
        let next=temp.next;
        let prev=temp.prev;
        next.prev=prev;
        prev.next=next;
    }
    }
    count++;
    temp=temp.next;
  }
  if(count===0){
    //item not found
    return null;
  }
}
// change code above this line
};
let dl=new DoublyLinkedList();
dl.add(34);
dl.add(34)
console.log(dl.head)




Your browser information:

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

Challenge: Create a Doubly Linked List

Link to the challenge:
https://www.freecodecamp.org/learn/coding-interview-prep/data-structures/create-a-doubly-linked-list

Why second argument is null?

Initially, I am making every new Node having previous to null. But I have changed it later, correctly. But my list is working correctly. I think another solution. Thanks for help.

You don’t need to create circular list in this challenge