Tell us what’s happening:
Hi, my code is not passing get method tests in fcc, however, they are producing the required output in chrome developer console and replit. Please help.
link :replit link
[Edit]: I have tried changing my code but still no luck. Anybody facing similar problem? Could it be an FCC bug or am I just doing something wrong here?
Updated code:
Your code so far
///////////////////////////////////////////////////////
/**Exercise: Fill in the object constructor with the following methods below:
//getFirstName() getLastName() getFullName() setFirstName(first) setLastName(last) setFullName(firstAndLast)//
Run the tests to see the expected output for each method.
The methods that take an argument must accept only one argument and it has to be a string.These methods must be the only available means of interacting with the object.
*/
////////////////////////////////////////////////////////
/**Note: Commented Out console.log() are for debugging only. */
//Function
var Person = function(firstAndLast) {
//Variable Declarations
var nameArray = firstAndLast.split(" "); // private property
/**publicly available method Get Methods */
this.getFullName = function() {
return nameArray.join(" ");
};
this.getFirstName = function() {
return nameArray[0];
};
this.getLastName = function() {
return nameArray[1];
};
/**publicly available method Set Methods */
this.setFullName = function(firstAndLast) {
nameArray = firstAndLast.split(" ");
};
this.setFirstName = function(first) {
nameArray[0] = first;
};
this.setLastName = function(last) {
nameArray[1] = last;
};
};
//Tests
/*Object bob created from person constructor function*/
var bob = new Person('Bob Ross');
console.log("_____________________________________");
console.log("bob instanceof Person: ", bob instanceof Person);//return true
/*Number of keys of the Object bob*/
console.log("_____________________________________");
console.log("Object.keys(bob).length: ", Object.keys(bob).length);//return 6
/*private property of object bob*/
console.log("_____________________________________");
console.log("bob.nameArray: ", bob.nameArray);//return undefined
/*public get methods of object bob*/
console.log("_____________________________________");
console.log("bob.getFullName(): ", bob.getFullName());//return "Bob Ross"
console.log("bob.getFirstName(): ", bob.getFirstName());//return "Bob"
console.log("bob.getLastName(): ", bob.getLastName());//return "Ross"
/*public set methods of object bob*/
console.log("_____________________________________");
bob.setFirstName("Haskell")
console.log("bob.setFirstName(\"Haskell\");");
console.log("bob.getFirstName(): ", bob.getFirstName());//return "Haskell"
console.log("bob.getLastName(): ", bob.getLastName());//return "Ross"
console.log("bob.getFullName(): ", bob.getFullName());//return "Haskell Ross"
console.log("_____________________________________");
bob.setLastName("Curry");
console.log("bob.setLastName(\"Curry\");");
console.log("bob.getFirstName(): ", bob.getFirstName());//return "Haskell"
console.log("bob.getLastName(): ", bob.getLastName());//return "Curry"
console.log("bob.getFullName(): ", bob.getFullName());//return "Haskell Curry"
console.log("_____________________________________");
bob.setFullName("Harry Potter");
console.log("bob.setFullName(\"Harry Potter\");");
console.log("bob.getFirstName(): ", bob.getFirstName());//return "Harry"
console.log("bob.getLastName(): ", bob.getLastName());//return "Potter"
console.log("bob.getFullName(): ", bob.getFullName());//return "Harry Potter"
console.log("_____________________________________");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36
.
Link to the challenge:
Updated Chrome console output: