5.1 KiB
id, title, challengeType, forumTopicId, dashedName
| id | title | challengeType | forumTopicId | dashedName |
|---|---|---|---|---|
| a2f1d72d9b908d0bd72bb9f6 | Creare una persona | 1 | 16020 | make-a-person |
--description--
Riempi il costruttore dell'oggetto con i seguenti metodi:
getFirstName()
getLastName()
getFullName()
setFirstName(first)
setLastName(last)
setFullName(first, last)
Esegui i test per vedere l'output atteso per ogni metodo. Questi metodi devono essere gli unici mezzi disponibili per interagire con l'oggetto. Ogni test dichiarerà una nuova istanza Person come new Person('Bob', 'Ross').
--hints--
Non dovresti cambiare la riga della dichiarazione della funzione.
assert.match(code, /const\s+Person\s*=\s*function\s*\(\s*first\s*,\s*last\s*\)\s*{/);
Non dovresti riassegnare il parametro first.
assert.notMatch(code, /first\s*=\s*/);
Non dovresti riassegnare il parametro last.
assert.notMatch(code, /last\s*=\s*/);
Nessuna proprietà dovrebbe essere aggiunta. Object.keys(Person).length dovrebbe sempre restituire 6.
const _person = new Person('Bob', 'Ross');
_person.setFirstName('Haskell');
_person.setLastName('Curry');
_person.setFullName('John', 'Smith');
assert.lengthOf(Object.keys(_person), 6);
Dovresti essere in grado di istanziare il tuo oggetto Person.
const _person = new Person('Bob', 'Ross');
assert.instanceOf(_person, Person);
L'oggetto Person non dovrebbe avere una proprietà firstName.
const _person = new Person('Bob', 'Ross');
assert.notProperty(_person, 'firstName');
L'oggetto Person non dovrebbe avere una proprietà lastName.
const _person = new Person('Bob', 'Ross');
assert.notProperty(_person, 'lastName');
Il metodo .getFirstName() dovrebbe restituire la stringa Bob.
const _person = new Person('Bob', 'Ross');
assert.strictEqual(_person.getFirstName(), 'Bob');
.getLastName() dovrebbe restituire la stringa Ross.
const _person = new Person('Bob', 'Ross');
assert.strictEqual(_person.getLastName(), 'Ross');
Il metodo .getFullName() dovrebbe restituire la stringa Bob Ross.
const _person = new Person('Bob', 'Ross');
assert.strictEqual(_person.getFullName(), 'Bob Ross');
Il metodo .getFullName() dovrebbe restituire la stringa Haskell Ross dopo aver chiamato .setFirstName('Haskell').
const _person = new Person('Bob', 'Ross');
_person.setFirstName('Haskell');
assert.strictEqual(_person.getFullName(), 'Haskell Ross');
Il metodo .getFullName() dovrebbe restituire la stringa Bob Curry dopo aver chiamato .setLastName('Curry').
const _person = new Person('Bob', 'Ross');
_person.setLastName('Curry');
assert.strictEqual(_person.getFullName(), 'Bob Curry');
Il metodo .getFullName() dovrebbe restituire la stringa Haskell Curry dopo aver chiamato .setFullName('Haskell', 'Curry').
const _person = new Person('Bob', 'Ross');
_person.setFullName('Haskell', 'Curry');
assert.strictEqual(_person.getFullName(), 'Haskell Curry');
Il metodo .getFirstName() deve restituire la stringa Haskell dopo aver chiamato .setFullName('Haskell', 'Curry').
const _person = new Person('Bob', 'Ross');
_person.setFullName('Haskell', 'Curry');
assert.strictEqual(_person.getFirstName(), 'Haskell');
Il metodo .getLastName() dovrebbe restituire la stringa Curry dopo aver chiamato .setFullName('Haskell', 'Curry').
const _person = new Person('Bob', 'Ross');
_person.setFullName('Haskell', 'Curry');
assert.strictEqual(_person.getLastName(), 'Curry');
Il metodo .getFullName() dovrebbe restituire la stringa Emily Martinez de la Rosa dopo aver chiamato .setFullName('Emily Martinez', 'de la Rosa').
const _person = new Person('Bob', 'Ross');
_person.setFullName('Emily Martinez', 'de la Rosa');
assert.strictEqual(_person.getFullName(), 'Emily Martinez de la Rosa');
La proprietà .getFirstName() dovrebbe restituire la stringa Emily Martinez dopo aver chiamato .setFullName('Emily Martinez', 'de la Rosa').
const _person = new Person('Bob', 'Ross');
_person.setFullName('Emily Martinez', 'de la Rosa');
assert.strictEqual(_person.getFirstName(), 'Emily Martinez');
La proprietà .getLastName() dovrebbe restituire la stringa de la Rosa dopo aver chiamato .setFullName('Emily Martinez', 'de la Rosa').
const _person = new Person('Bob', 'Ross');
_person.setFullName('Emily Martinez', 'de la Rosa');
assert.strictEqual(_person.getLastName(), 'de la Rosa');
--seed--
--seed-contents--
const Person = function(first, last) {
this.getFullName = function() {
return "";
};
return "";
};
--solutions--
const Person = function(first, last) {
let firstName = first;
let lastName = last;
this.getFirstName = function(){
return firstName;
};
this.getLastName = function(){
return lastName;
};
this.getFullName = function(){
return firstName + " " + lastName;
};
this.setFirstName = function(str){
firstName = str;
};
this.setLastName = function(str){
lastName = str;
};
this.setFullName = function(first, last){
firstName = first;
lastName = last;
};
};