Problem
Hey, I’m seeing some weird stuff here. I’m working on Make a Person challenge and tests doesn’t let me finish although I have it all right.
If I ask for
bob.setFirstName(“Haskell”);
bob.getFullName();
it gives me that all is right and return “Haskell Ross” like it shoud. But if I just ask for “bob.getFullName();” (without setting a name) it suddenly become incorrect (but it shows the name like it should!!!) I’ve checked via external code editor - and it works fine. Could someone please explain what’s going on?
Code
var Person = function(firstAndLast) {
var memory = [];
this.getFullName = function() {
if (memory.length === 0) {
memory.push(firstAndLast);
return memory.join();
}
return memory[0];
};
this.getFirstName = function() {
return memory[0].split(' ')[0];
};
this.getLastName = function() {
return memory[0].split(' ')[1];
};
this.setFirstName = function(firstName) {
memory.push(firstName +' '+ firstAndLast.split(' ')[1]);
};
this.setLastName = function (lastName) {
memory.push(firstAndLast.split(' ')[0] + ' ' +lastName);
};
this.setFullName = function (fullName) {
memory.push(fullName);
};
return firstAndLast;
};
var bob = new Person('Bob Ross');
bob.setFirstName("Haskell"); //▾▾▾
bob.getFullName(); // they're working, but the test denies it!