Javascript objects gatters and setters 2 - question


Hi there , if i want to print to the console the final age of the person - where should i put the console.log line? everytime i try it says that that line is not a function :frowning:
the final code is :slight_smile:

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’;

person.age = 39;

// i just want to print to the console the …age – and i dont know where to put that code line without getting the error thats “not a function”

Thank you guys !!

person.age = 39;

The only way console.log() is not a function is if we overwrite it (a common error):

console.log = "some string"

attempting to log something after a statement like this will result in an error. Restore the JS namespace by doing a hard refresh (Ctrl+F5).


Thank you !:grinning::grinning::grinning::grinning:


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