Question: I am trying to build a function that checks if all fields are populated, if populated then show div if not hide.

I can get this to work on one fields however i have then tried two ways of checking multiple.

**first**
if first condition met I then ran other condition checking second field nested inside the first... this done not work.

**second**
I passed in an array of ID's rather than a single... this did not work either..

I am left with a working function that only works if first filed is populated can anyone think of a solution to this or maybe i passed in my array incorrectly.

**My code** 

```
var myVar = setInterval(myTimer, 10);

function myTimer() {

if(!document.getElementById('Email').value) { // I need this to pass if multiple id's
          var divsToHide = document.getElementsByClassName("somediv"); //divsToHide is an array
            for(var i = 0; i < divsToHide.length; i++){
                divsToHide[i].style.visibility = "hidden"; // or
                divsToHide[i].style.display = "none"; // depending on what you're doing

        }
    }
  else {
   var divsToHide = document.getElementsByClassName("somediv"); //divsToHide is an array
            for(var i = 0; i < divsToHide.length; i++){
                divsToHide[i].style.visibility = "visible"; // or
                divsToHide[i].style.display = "block"; // depending on what you're doing
  }
  }
}

```

Answer: 
If you have an array of the IDs such as 

```
let idArray = ['foo', 'bar', 'baz']

```

You can iterate through an array using a `for` loop

```
for (i = 0; i > idArray.length; i++) {
    if (!document.getElementById(idArray[i]).value) { 
        // your hide logic
    } else {
        // your show logic
    }
}

```
You can create a const of all elements that need to validate. For example,

```
const elementIdsToBeValidated = ['name', 'email'];

```

You can also create validator functions that returns true and false based on input,

```
const nameValidator = (val) => !!val;
const emailValidator = (email) => !!email;

const validators = [nameValidator, emailValidator];

```

Then you can run your timer function,

```
var myVar = setInterval(myTimer(['name', 'email']), 10);

function myTimer(ids) {
  ids.forEach(id => {
    const el = document.getElementById(id);
    const val = el.value;
    const divEl = document.getElementById('error');
    const valid = validators.reduce((acc, validator) => validator(val), false);
    if(valid) {
      divEl.style.display = 'none';
    } else {
      divEl.style.display = 'block';
    }
  });
}

```

You can look at this stackBlitz example,
<https://stackblitz.com/edit/js-ie7ljf>