Start by adding an empty .age() setter method


#1

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

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

};

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

‘’’


#2

That needs to be inside the object.


#3

I tried it and it didn’t work.

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

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

‘’’


#4

Remember to separate all attributes with a comma.


#5

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


#6

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');
    }
  }
};

#7

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


#8

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';}
  }
  };

#9
    this._age = ageIn;

#10

thank you:grinning::grinning: