Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Person = function (firstAndLast) {
- // Only change code below this line
- // Complete the method below and implement the others similarly
- let arr = [];
- let counterLastName = 0;
- let counterFirstName = 0;
- let counterFullName = 0;
- this.setFirstName = function (firstName) {
- counterFirstName++;
- arr.push(firstName);
- return firstName;
- }
- this.setLastName = function (lastName) {
- counterLastName++;
- arr.push(lastName);
- return lastName;
- }
- this.setFullName = function (fullName) {
- counterFullName++;
- arr = fullName.split(' ');
- console.log(arr);
- return fullName;
- }
- this.getFullName = function () {
- if (counterFullName > 0) {
- return `${arr[0]} ${arr[1]}`;
- } else if (arr.length === 1 && counterFirstName > 0) {
- return `${arr[0]} ${this.getLastName()}`;
- } else if (arr.length === 1 && counterLastName > 0) {
- return `${this.getFirstName()} ${arr[0]}`;
- } else if (arr.length === 2) {
- return `${arr[0]} ${arr[1]}`;
- } else {
- return `${this.getFirstName()} ${this.getLastName()}`;
- }
- };
- this.getFirstName = function () {
- if (counterFullName > 0) {
- return `${arr[0]}`;
- } else {
- return firstAndLast.split(' ')[0];
- }
- }
- this.getLastName = function () {
- if (counterFullName > 0) {
- return `${arr[1]}`;
- } else {
- return firstAndLast.split(' ')[1];
- }
- }
- return;
- };
- var bob = new Person('Bob Ross');
- // bob.setFirstName("Haskell");
- // bob.setLastName("Curry");
- bob.setFullName("Haskell Curry");
- console.log(bob.getFullName());
- console.log(bob.getFirstName());
- console.log(bob.getLastName());
- console.log(Object.keys(bob).length);
- console.log(Object.keys(bob));
- console.log(bob['setFirstName']);
Advertisement
Add Comment
Please, Sign In to add comment