26/30 Passing arguments


#1

https://www.codecademy.com/en/courses/objects-ii/4/5?curriculum_id=506324b3a7dffd00020bf661#

Why is the if/else statement without ankle bracelets?


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 "Wrong password.";
   };
}

Replace this line with your code.


#2

@sotu,

To see how this works, this is how it would look like if the nesting were properly indented:

if (condition1)
   statement1
else
   if (condition2)
      statement2
   else
      if (condition3)
...12345678

To execute multiple statements within a clause, use a block statement ({ ... }) to group those statements. In general, it is a good practice to always use block statements, especially in code involving nested if statements:

if (condition) {
   statements1
} else {
   statements2
}12345

https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Statements/if...else


#3

@leonhard.wettengmx.n Thabk you for answering. It is clear now.


#4

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