24 / problem?


#1

Bonjour, j'ai un petit soucis avec cet exercice, quelqu'un voit ou j'ai pu me tromper ?

function Personne(prenom,nom,age) {
this.prenom = prenom;
this.nom = nom;
this.age = age;
var compteEnBanque = 7500;

this.getCompte = function() {
// votre code doit retourner le compteEnBanque
return compteEnBanque
};
}

var john = new Personne('John','Smith',30);
console.log(john.compteEnBanque);

// Créez une nouvelle variable monCompte qui appelle getCompte()
var monCompte = john.getCompte

console.log(monCompte)

Merci de votre coup de mains !!


#2

Perhaps you could describe the problem?

What's happening and what should happen instead?


#3

i just find the solution, i missed a () after :
var monCompte = john.getCompte
Now it's working !
thanks


#4

I had the same probalme, I dont understand though, why i had to add the () to the john.getBalance like this:
var myBalance = john.getBalance();

why it is not enough to write:
var myBalance = john.getBalance;


#5

You must write the line:

var myBalance = john.getBalance();

because "get.Balance()" is a method.

If you only wrote:

var myBalance = john.getBalance;

Those parentheses on the end indicate a function or method. Javascript would think "getBalance" is a variable that perhaps has not yet been created.