23. Private Variables

This is not working and i dont get why its not!!

```

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

// create your Person
var john = new Person(‘Mou’, 12);
var bankBalance();
console.log(john.bankBalance);
// try to print his bankBalance

<do not remove the three backticks above>Continuing the discussion from [Private variables](https://discuss.codecademy.com/t/private-variables/16097):

Hi just remove that line

var bankBalance();

yes i tried removing it but its showing undefined then!! why so?! its not printing what it should print!

Another thing to fix is the fact that your constructor has three arguments, but you only use two when creating the Person object. John need both a first and last name.

@mou_me yes, it’s the right result because you are trying to eccess to a private variable

still its showing undefined :unamused:

ohh i see!!! thanks btw :open_mouth:

1 Like

you can’t access the private variable.
The result is correct.

check below code…

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

// create your Person

var john = new Person(“Jogh”, “p”, 10);

// try to print his bankBalance

console.log(john.bankBalance);

write

console.log( Person(bankBalance) );

A post was split to a new topic: 23. private variables