@jp2kk2/

Person Name constructor

JavaScript

No description

fork
loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
var Person = function(firstAndLast) {
    // Complete the method below and implement the others similarly
    this.getFullName = function(){
      return firstAndLast;
    };
    this.getFirstName = function(){
      return firstAndLast.split(" ")[0];
    };
    this.getLastName = function(){
      return firstAndLast.split(" ")[1];
    };
    this.setFirstName = function(name){
      firstAndLast = firstAndLast.split(" ");
      firstAndLast[0]=name;
      firstAndLast= firstAndLast.join(" ");
      return firstAndLast;
    };
    this.setLastName = function(name){
      firstAndLast = firstAndLast.split(" ");
      firstAndLast[1]=name;
      firstAndLast= firstAndLast.join(" ");
      return firstAndLast;
    };
    this.setFullName = function(name){
      firstAndLast=name;
      return firstAndLast;
    };
};

var bob = new Person('Bob Ross');
bob.getFullName;
Native Browser JavaScript