Question: I need to design a global boolean with 2 conditions a and b such that if A is ever true, the boolean is true until b is true, at which point the boolean is false. In other words, if A becomes false the boolean remains true.

I tried a straightforward global variable but it became false when A became false.

Preferably JavaScript, but pseudocode would be almost as helpful.

Answer: 
Javascript old-school way:

```
function Enjoy() {
    this.a = true;
    this.b = true;
    this.bool = true;
}

Enjoy.prototype = {
    constructor: Enjoy,

    setA: function( val ) {
        this.a = val;
        if ( this.a === true && this.b === true ) this.bool = false;
        else if ( this.a === true && this.b === false ) this.bool = true;
    },

    setB: function( val ) {
        this.b = val;
        if ( this.a === true && this.b === true ) this.bool = true;
        else if ( this.a === true && this.b === false ) this.bool = false;
    },

    getBool: function() {
        return this.bool;
    }
};

var enjoy = new Enjoy();
enjoy.getBool(); // true
enjoy.setB( false );
enjoy.getBool(); // false

```

As you can see, the idea is to use getters/setters for your boolean and both `a` and `b` variables where you do all your logic.

By the way, this question is definitely for StackOverflow.
Based on some assumptions about how B should behave if A has not been true:

```
function FlipFlop(){
    this.latch = false;
    this.value = false;
}

FlipFlop.prototype = {
    constructor: FlipFlop,

    setA: function( val ) {
        this.latch = this.latch || !!val;
        this.value = this.latch;
    },

    setB: function( val ) {
        if(this.latch && !!val) {
            this.latch = false;
        }
        this.value = !val;
    },

    getVal: function() {
        return this.value;
    }
}

```