Tell us what’s happening:
getting error : Cannot read property ‘element’ of null, need help
Your code so far
function LinkedList() {
var length = 0;
var head = null;
var Node = function(element){
this.element = element;
this.next = null;
};
this.head = function(){
return head;
};
this.size = function(){
return length;
};
this.isempty=function(){
if(this.head==null){
return true;
}else{
return false;
}
}
this.add = function(element){
// Only change code below this line
let newNode= new Node(element);
if(this.isempty){
head=newNode;
length++;
}else{
let current=this.head;
while(current.next<null){
current++;
}current.next=newNode;
length++;
}
// Only change code above this line
};
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/coding-interview-prep/data-structures/create-a-linked-list-class