Have tested this code in Firefox, and all the test challenges do match in the browser’s console just fine.
The test errors in the last line of challenge, telling that (what appears in the console.log correctly) is expected?
Your code so far
var Person = function(firstAndLast) {
// Complete the method below and implement the others similarly
var init = firstAndLast.split(" ");
this.setFullName = function(arg){
init.splice(0,2);
init.push(arg.split(" "));
this.setFullName.kid = init[0];
};
this.setFirstName = function(first){
if(!this.setFullName.kid){
init[0] = first;
this.setFirstName.kid = init[0];
}
else{
this.setFullName.kid[0] = first;
this.setFirstName.kid = this.setFullName.kid[0];
}
};
//--------------------------------------------------------------------
this.setLastName = function(last){
if(!this.setFullName.kid){
init[1] = last;
this.setLastName.kid = init[1];
}
else{
this.setFullName.kid[1] = last;
this.setLastName.kid = this.setFullName.kid[1];
}
};
this.getFullName = function(){if(!this.setFullName.kid){
return init.join(" ");
}
var exporty = this.setFullName.kid;
return exporty.join(" ");
};
this.getFirstName = function(){if(!this.setFirstName.kid){
return init[0];
}
return this.setFirstName.kid;
};
this.getLastName = function(){if(!this.setLastName.kid){
return init[1];
}
return this.setLastName.kid;
};
};
var bob = new Person('Bob Ross');
console.log(bob.getFullName());
console.log(bob.getFirstName());
console.log(bob.getLastName());
console.log(bob.getFullName());
bob.setFirstName("Haskell");
console.log(bob.getFullName());
bob.setLastName("Curry");
console.log(bob.getFullName());
bob.setFullName("Haskell Curry");
console.log(bob.getFirstName());
bob.setFullName("Haskell Curry");
console.log(bob.getLastName());
// It errors this last line, but the browser displays accordingly.
Your browser information:
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person