-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathfixName.js
24 lines (19 loc) · 866 Bytes
/
fixName.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
/*
We want to create a constructor function 'NameMe', which takes first name and last name as parameters. The function combines the first and last names and saves the value in "name" property.
We already implemented that function, but when we actually run the code, the "name" property is accessible, but the "firstName" and "lastName" is not accessible. All the properties should be accessible. Can you find what's wrong with it? A test fixture is also available
function NameMe(first, last) {
this.firstName = first;
this.lastName = last;
return {name: this.firstName + ' ' + this.lastName};
}
var n = new NameMe('John', 'Doe');
n.firstName //Expected: John
n.lastName //Expected: Doe
n.name //Expected: John Doe
*/
//Answer//
function NameMe(first, last) {
this.firstName = first;
this.lastName = last;
this.name = first +' '+ last
}