Fortuna Iwasaki Fortuna Iwasaki - 1 year ago 39
Javascript Question

Creating a random number generator in HTML

I'm trying to create a webpage the looks like a health monitor and I need to create a random number generator that will act as the heart monitor. Here is what I have:


function functionName()
return rand(5, 15);




$i = 0;

while ($i <= 10)
echo functionName();
echo "</br>";



The problem is that number are printed one after another and I need them to just show up in the same place but be different. In other words if I have a section that says "Heart Best Per Seconds: ", I will need a new number to show up there every few seconds in place of the other.

Does anyone know how to do this? I've seen things similar to this so I'm pretty sure that it's doable.


setInterval(function() {
  var i = Math.floor(Math.random() * (15 - 5 + 1)) + 5;
  document.getElementById("random").innerHTML = i;
}, 1000);
 <span id="random"></span>

this maybe? using Math.random(); and setInterval()