FreeCodeCampChina / freecodecamp.cn

FCC China open source codebase and curriculum. Learn to code and help nonprofits.
https://fcc.asia/
Other
36.73k stars 1.36k forks source link

[Make a Person] has a bug #632

Open Kenvas opened 4 years ago

Kenvas commented 4 years ago

Challenge [Make a Person](https://freecodecamp.cn/challenges/make-a-person#?solution=var%20Person%20%3D%20function(firstAndLast)%20%7B%0A%20%20%20%20var%20firstName%3D%22%22%3B%0A%20%20%20%20var%20lastName%3D%22%22%3B%0A%20%20%20%20this.getFirstName%3Dfunction()%7B%0A%20%20%20%20%20%20%20%20console.log('getFirstName'%2CfirstName)%3B%0A%20%20%20%20%20%20%20%20return%20firstName%3B%0A%20%20%20%20%7D%3B%0A%20%20%20%20this.getLastName%3Dfunction()%7B%0A%20%20%20%20%20%20%20%20console.log('getLastName'%2ClastName)%3B%0A%20%20%20%20%20%20%20%20return%20lastName%3B%0A%20%20%20%20%7D%3B%0A%20%20%20%20this.getFullName%3Dfunction()%7B%0A%20%20%20%20%20%20%20%20var%20retval%3D%5BfirstName%2C%20lastName%5D.join('%20')%3B%0A%20%20%20%20%20%20%20%20console.log('getFullName'%2Cretval)%3B%0A%20%20%20%20%20%20%20%20return%20retval%3B%0A%20%20%20%20%7D%3B%0A%20%20%20%20this.setFirstName%3Dfunction(x)%7B%0A%20%20%20%20%20%20%20%20console.log('setFirstName'%2Cx)%3B%0A%20%20%20%20%20%20%20%20firstName%3Dx%3B%0A%20%20%20%20%7D%3B%0A%20%20%20%20this.setLastName%3Dfunction(x)%7B%0A%20%20%20%20%20%20%20%20console.log('setLastName'%2Cx)%3B%0A%20%20%20%20%20%20%20%20lastName%3Dx%3B%0A%20%20%20%20%7D%3B%0A%20%20%20%20this.SetFullName%3Dfunction(x)%7B%0A%20%20%20%20%20%20%20%20var%20arr%3Dx.split('%20')%3B%0A%20%20%20%20%20%20%20%20console.log('SetFullName'%2C%20arr)%3B%0A%20%20%20%20%20%20%20%20firstName%3Darr%5B0%5D%3B%0A%20%20%20%20%20%20%20%20lastName%3Darr%5B1%5D%3B%0A%20%20%20%20%7D%3B%0A%20%20%20%20this.SetFullName(firstAndLast)%3B%0A%20%20%20%20return%20this%3B%0A%7D%3B%0A%0Avar%20bob%20%3D%20new%20Person('Bob%20Ross')%3B%0A) has an issue. User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0. Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:

var Person = function(firstAndLast) {
    var firstName="";
    var lastName="";
    this.getFirstName=function(){
        console.log('getFirstName',firstName);
        return firstName;
    };
    this.getLastName=function(){
        console.log('getLastName',lastName);
        return lastName;
    };
    this.getFullName=function(){
        var retval=[firstName, lastName].join(' ');
        console.log('getFullName',retval);
        return retval;
    };
    this.setFirstName=function(x){
        console.log('setFirstName',x);
        firstName=x;
    };
    this.setLastName=function(x){
        console.log('setLastName',x);
        lastName=x;
    };
    this.SetFullName=function(x){
        var arr=x.split(' ');
        console.log('SetFullName', arr);
        firstName=arr[0];
        lastName=arr[1];
    };
    this.SetFullName(firstAndLast);
    return this;
};

var bob = new Person('Bob Ross');