Passing Arguments (Passando Argumentos)


#1

Hello,

I am in lesson "Passing Arguments", but unable to move forward, as the code fails, with the error below.

I really cannot see what is wrong. Thanks in advance.

the code is:

function Person(first,last,age) {
   this.firstname = first;
   this.lastname = last;
   this.age = age;
   var bankBalance = 7500;
  
   this.askTeller = function(pass) {
     if (pass == 1234) {
         return bankBalance;
     } else {
         return "Senha incorreta.";
     }
   };
}

var john = new Person('John','Smith',30);
/* a variável myBalance deve acessar askTeller()
   com uma senha como argumento  */

var myBalance = john.askTeller('1234');


#2

you should invocking this way :smile:

john.askTeller('1234');

if still not work try console.log instesad of return


#3

Hello obin100,

Thanks for the response, but the lesson requires me to assign the returned value into the myBalance variable.

The console.log() should just print the content of the variable.

The method is to RETURN, not print, so the need to assign the value.

I believe that the code is correct,since even the TIP is written this way.

Thanks again.


#4

I assume you have passed the lesson, but like i said in first comments when invoking function you don't need to assign the invoking into variable, that is why it wont invoke the function, since i don't speak Spanish I don't realy get what the problem is.


#5

obin100, hello again!

I did not passed the lesson, because I cannot move on without solving this issue.

I understand that for executing a method, there is no need to assign the result into a variable, but, that is exactly what the lesson asks.
Mine is in portuguese, but, the superficial translation would be "Create a new variable called 'myBalance' which calls the 'askTeller' function with an password argument '1234'!"

That is exactly what I am doing, but the editor keeps telling me that the variable was not assigned, thus, it is wrong!

Sorry if I am not making myself very clear, but my english is not native.

Thanks again for your time!


#6

i'm not native english too

function Person(first,last,age) {
   this.firstname = first;
   this.lastname = last;
   this.age = age;
   var bankBalance = 7500;
  
   this.askTeller = function(pass) {
     if (pass == 1234) {
         return bankBalance;
     } else {
         return "Senha incorreta.";
     }
   };
}

var john = new Person('John','Smith',30);
/* a variável myBalance deve acessar askTeller()
   com uma senha como argumento  */

john.askTeller(1234);// maybe if you put number instead of string it will work

when i checked (no error) wether i console log it or return i tried string and number, both work


#7

obin100

I could smash my head over a wall now.
The problem was "data type" in fact, when I put number there on the argument, it worked.

Sorry the waste of time, for such a simple problem.

Thank you for pointing that out.


#8

is it work? glad to hear that