23. Private Variables


#1

function Person(first,last,age) {
this.firstname = first;
this.lastname = last;
this.age = age;
var bankBalance = 7500;
}

// create your Person
var john = Person("John", "Son", 36);

// try to print his bankBalance
console.log(john.bankBalance);

This is my code, but the page says: "Oops, try again. Make sure to create john using the Person constructor". What's wrong in my code?


#2

Use 'new' keyword to create an object.
var john = new Person("John", "Son", 36);


#3

Thanks! I missed that part :frowning:


#4

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