Getters & Setters - Use typeof method in an if statement (error: No print)


I am working on this exercise (Link to Getters and Setters)

I am using typeof method in an if statement to check if the input value is a number. When I run the code nothing is showing up. There is no error message so I don’t know where to look.

My code is below. Could you please guide me.

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

 set age(mynumber) {
  if (typeof mynumber === number) {
    this.age = mynumber; 
    console.log(`${mynumber} is valid input`);
   else {
     console.log('Invalid input');


Check out the MDN docs on the typeof operator.

Notice that the data type is in string format.


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