Q:

how could I display more than one if/else to one ID?

say two of the if statements below are true, how could I make them write to the same tag at different times.
if (a===b) {
        document.getElementById("LW").innerHTML = "statement 1"
    }
else  if (c===d) {
        document.getElementById("LW").innerHTML = "statement 2"
    }
else  if (e===f) {
        document.getElementById("LW").innerHTML = "statement 3";
    }
else {
        document.getElementById("LW").innerHTML = "";
    }

It would go to this
<p id="LW"></p>

for example, if two of the if statements were true, could it be possible to have one statement write to the p tag for 3 seconds, then display the next true statement? maybe a function or setTimer?
i have tried many ideas and searched all over but I can't seem to figure this one out! any help would be great! thanks in advance, I can try to explain further if necessary!

A:

I am not sure what you are trying to achieve here. But one solution I can think of is not to use if-else, rather use just if statements and add all possible contents that needs to displayed to a array..
Later with an interval, you can keep toggling the contents of the array.

<!DOCTYPE html>
<html>

<body>

 <p>Click the button.</p>

 <button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
  document.getElementById('LW').value = 'statement 1';
  var contents = [];
  var i = 0;
  var count = 0;
  var a=1, b=1,c=2,d=2,e=3,f=3, g=4, h=5;
  if (a === b) {
    contents.push("statement 1");
    count++;
  }
  if (c === d) {
    contents.push("statement 2");
    count++;
  }
  if (e === f) {
    contents.push("statement 3");
    count++;
  }

  if (g === h) {
    contents.push("statement 3");
    count++;
  }

    setInterval(function(){ 
    i++;
    document.getElementById('LW').value = contents[i%count] 
  }, 1000);
}

</script>

            <label for="LW"></label><input type="text" id="LW"><label id="LWlabel"></label>
</body>
</html>

