-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmake-a-person.js
40 lines (31 loc) · 977 Bytes
/
make-a-person.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
32
33
34
35
36
37
38
39
40
// Make a Person
/*
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.
*/
const Person = function(firstAndLast) {
let name = firstAndLast;
this.getFirstName = () => {
return name.split(' ')[0];
};
this.getLastName = () => {
return name.split(' ')[1];
};
this.getFullName = () => {
return name;
};
this.setFirstName = (first) => {
name = `${first} ${name.split(' ')[1]}`;
};
this.setLastName = (last) => {
name = `${name.split(' ')[0]} ${last}`;
};
this.setFullName = (firstAndLast) => {
name = firstAndLast;
};
};
const bob = new Person('Bob Ross');
bob.getFullName();