Why test not pass please explain

Tell us what’s happening:

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;

          currentNode  = currentNode.next;

      currentNode.next = node;


this.remove = function(element){
  // Only change code below this line
   let currentNode = head;
   let previous;
 if(currentNode.element===element ){
   head = currentNode.next}

     while(currentNode.element !==element ){
       previous = currentNode ;
       currentNode = currentNode.next;
     previous.next = currentNode.next;

  // Only change code above this line

Your browser information:

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

Challenge: Remove Elements from a Linked List

Link to the challenge:

This is the error i see when running your code:

Your remove method should not change the linked list if the element does not exist in the linked list.

This is your code

if(currentNode.element===element ){...}

If the element does not exists the else path will be triggered, modifying the list. I think an additional check is needed if you want to keep your code as is^^