dimanche 14 mars 2021

How to make events equate to TRUE or FALSE

How do I declare an event so that when it happens, a variable becomes TRUE but when it's not happening, it's FALSE?

For example:

let x = /*Event of an input being focused or an input has text*/
let a;

if ( /*x event criteria is met*/ ) {
  a = true;
} else /*x event criteria is not met*/ {
  a = false;
}

From the example above, how do I get to reference the value of a outside of the if statements?

if ( a == true ) {
  console.log('on focus or has text!');
}
if ( a == false) {
  console.log('empty and on blur!');
}

I strictly cannot make functions inside the first if statements or, in the example's case, put the console.log() inside the if statements where it detects if the event criteria is met or not.

Aucun commentaire:

Enregistrer un commentaire