Make a Person
28-ой день программы "#100 Days Of Code"
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.
Here are some helpful links:
var Person = function(firstAndLast) {
var namesArr = firstAndLast.split(" ");
this.getFirstName = function(){
return namesArr[0];
};
this.getLastName = function(){
return namesArr[1];
};
this.getFullName = function(){
return namesArr.join(" ");
};
this.setFirstName = function(first){
namesArr[0] = first;
};
this.setLastName = function(last){
namesArr[1] = last;
};
this.setFullName = function(firstAndLast){
namesArr = firstAndLast.split(' ');
};
return firstAndLast;
};
var bob = new Person('Bob Ross');
bob.getFullName();
Комментариев нет:
Отправить комментарий