vendredi 8 mai 2020

Complex if-else statement in Javascript [closed]

This is the code that is not working. It returns me false even when it has to return true:

public isBeingEdited(): any {
    if (this.singerData && (this.singerData.name === "John" ||
        this.singerData.ageDead === 40 ||
        this.singerData.yearDead === 1980)) {
        return true;
    }
    return false;
}

There should be only three ways to return true:

if this.singerData AND this.singerData.name === "John" return true,

if this.singerData AND this.singerData.ageDead === 40 return true,

if this.singerData AND this.singerData.yearDead === 1980 return true

So, this.singerData is true AND any of the next in parenthesis is true. All others should return false.

Please let me know if unclear.

Aucun commentaire:

Enregistrer un commentaire