Intermediate Algorithm Scripting - Make a Person

This doesn’t make sense to me.
The exercise asks to write set methods and set methods set properties.
If there are no properties then what exactly would the set methods set?

I also never understood why there are no links to the relevant lessons that came before the exercise so that one may retry those to remember how it works.
Any links to them?

const Person = function(firstAndLast) {
  // Only change code below this line
  // Complete the method below and implement the others similarly
  this.firstAndLast = firstAndLast;

  this.getFirstName = function() {return this.firstAndLast.split(' ')[0];};
  this.getLastName = function() {return this.firstAndLast.split(' ')[1];};
  this.getFullName = function() {
    return this.firstAndLast;

  this.setFirstName = function(first){
    this.firstAndLast = first + ' ' + firstAndLast.split(' ')[1];

  this.setLastName = function(last){
    this.firstAndLast = firstAndLast.split(' ')[0] + ' ' + last;

  this.setFullName = function(firstAndLast){
    this.firstAndLast = firstAndLast;

  return firstAndLast;

const bob = new Person('Bob Ross');

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Intermediate Algorithm Scripting - Make a Person

Link to the challenge:

Hint 2

The program has a test that checks for how many keys you used, they have to be exactly six, the six mentioned in the details section. This means if you need to work with variables, make them local and not a key.

let fullName  = firstAndLast;

so you may then have:

this.getFirstName = function() { return fullName.split(' ')[0] }
1 Like

Should be this one, though it needs some thinking about if it’s a local variable => it isn’t a property that counts towards the properties here

1 Like

altho i don’t get why this doesn’t work:

const Person = function(firstAndLast) {

  // let fullName  = firstAndLast;
  this.getFirstName=() =>  firstAndLast.split(' ')[0] 


i mean, this works:

const Person = function(firstAndLast) {

  let fullName  = firstAndLast;

  this.getFirstName=() =>   fullName.split(' ')[0] 

I think it’s because firstAndLast is an argument passed to Person() when making a person but when that function/constructor call is finished the variable is gone.
When variables are passed to a function, those arguments do not persist after the function call is over as far as I know but javascript might be different(although I personally doubt it)

I hope that makes sense to you and if not that someone can explain better than me(and correct it if I am wrong)

no, i think it’s storing a name in memory. remember it is an object constructor and the object is stored as a const in this case (altho it wouldn’t matter if it isn’t a const i think)

yes, i seem to have it working now altho the console is throwing strange errors. dunno if it’s a cache issue here. anyway, thanks.
altho the test seems to fail (weirdly imo) if i try to use that notation.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.