Why does the following code return 'the value of bool1 is incorrect':
class NoDefaultParams {
constructor(num1, num2, num3, string1, bool1) {
this.num1 = num1;
this.num2 = num2;
this.num3 = num3;
this.string1 = string1;
this.bool1 = bool1;
}
calculate() {
if (this.bool1) {
console.log(this.string1, this.num1 + this.num2 + this.num3);
return;
}
return 'The value of bool1 is incorrect';
}
}
var fail = new NoDefaultParams(1, 2, 3, "test", false);
console.log(fail.calculate());
And why does the following code return the calculate()
method:
class NoDefaultParams {
constructor(num1, num2, num3, string1, bool1) {
this.num1 = num1;
this.num2 = num2;
this.num3 = num3;
this.string1 = string1;
this.bool1 = bool1;
}
calculate() {
if (this.bool1) {
console.log(this.string1, this.num1 + this.num2 + this.num3);
return;
}
return 'The value of bool1 is incorrect';
}
}
var fail = new NoDefaultParams(1, 2, 3, "test", true);
console.log(fail.calculate());
Are they both not boolean values? the if
statement is just looking for the property whether it is true or false correct? What am I missing? Why can't the boolean argument be false?
Comments
Post a Comment