-
Notifications
You must be signed in to change notification settings - Fork 0
/
Make-a-Person.js
57 lines (50 loc) · 1.44 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
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.
*/
var Person = function(firstAndLast) {
/*Setters*/
this.setFirstName = function(first){
var current = firstAndLast.split(' ');
current[0] = first;
firstAndLast = current.join(' ');
firstName = first;
};
this.setLastName = function(last){
var current = firstAndLast.split(' ');
current[1] = last;
firstAndLast = current.join(' ');
lastName = last;
};
this.setFullName = function(newfirstAndLast){
firstAndLast = newfirstAndLast;
};
/*Getters*/
// Complete the method below and implement the others similarly
this.getFirstName = function() {
return firstAndLast.split(' ')[0];
};
this.getLastName = function() {
return firstAndLast.split(' ')[1];
};
this.getFullName = function() {
return firstAndLast;
};
return firstAndLast;
};
var bob = new Person('Bob Ross');
console.log(bob.getFullName());
console.log(bob.getFirstName());
console.log(Object.keys(bob).length);
bob.setFirstName("Haskell");
console.log(bob.getFullName());
bob.setLastName("Curry");
console.log(bob.getFullName());