-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalgorithm20.html
71 lines (49 loc) · 1.22 KB
/
algorithm20.html
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html>
<body>
<script>
//https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person
//Fill in the object constructor with the given methods
function Person(firstAndLast) {
// Complete the method below and implement the others similarly
var firstName, lastName;
function getFN() {
return `${firstName} ${lastName}`;
};
function setFN(n) {
[firstName, lastName] = n.split(' ');
}
setFN(firstAndLast);
function getFirstN(){
return firstName;
}
function getLastN(){
return lastName;
}
this.getFullName = getFN;
this.setFullName = setFN;
this.getFirstName = getFirstN;
this.setFirstName = function(n){
firstName = n;
};
this.getLastName = getLastN;
this.setLastName = function(n){
lastName = n;
};
return this;
};
var bob = new Person('Bob Ross');
bob.setFirstName("Haskell");
bob.setLastName("Curry");
//tests
console.log(bob);
console.log(Object.keys(bob).length);
console.log(bob instanceof Person);
//console.log(bob.firstName());
//console.log(bob.lastName());
console.log(bob.getFirstName());
console.log(bob.getLastName());
console.log(bob.getFullName());
</script>
</body>
</html>