Start by adding an empty .age() setter method

I’m not sure if I am doing this right.

‘’’
let person = {
_name: ‘Lu Xun’,
_age: 137

};

set age(ageIn){this.age=ageIn;}

‘’’

That needs to be inside the object.

I tried it and it didn’t work.

‘’’
let person = {
_name: ‘Lu Xun’,
_age: 137

set age(ageIn){this.age=ageIn;}
};

‘’’

Remember to separate all attributes with a comma.

ahh. okay. Thanks.:grinning::grinning:

1 Like

Create a conditional statement to check if a user’s input is a number.

If the input is a number, set the _age property to the input value. If the input is not a number, return the string, ‘Invalid input’.

can you check my code?

let person = {
  _name: 'Lu Xun',
  _age: 137,
  set age(ageIn){
    if (typeof ageIn==='number'){
      this.age=ageIn;
    } else {
      console.log('Invalid input');
    }
  }
};

Whitespace helps with reading and discovering errors. In your code, the if was capitalized when it should not be.

Did you set the age property inside your conditional?

let person = {
  _name: 'Lu Xun',
  _age: 137,

  set age(ageIn){
    if (typeof ageIn==='number'){
      this.age=ageIn;
}
else {console.log('Invalid input');
     return 'Invalid input';}
  }
  };
    this._age = ageIn;

thank you:grinning::grinning:

1 Like