I'm having trouble applying my function to multiple elements. My goal is to have each element change individually on its own.
Currently, only the first element is changing. I want all three of them to change separately.
For instance:
Not Available
Available
Available
var updateVar = setInterval(updateStatus, 2000);
function updateStatus() {
var status = Math.random();
if (status < 0.90) {
str = "Available";
message = str.fontcolor("green");
available = true;
} else {
str = "Not Avaliable";
message = str.fontcolor("red");
available = false;
}
var elements = Array.from(document.querySelectorAll('.demo'));
for (const elem of elements) {
elem.innerHTML = message;
break;
}
}
<p id="demo1" class="demo"></p>
<p id="demo2" class="demo"></p>
<p id="demo3" class="demo"></p>