vendredi 11 décembre 2020

How is it that im putting the correct number into my random number code and it is not registering certain numbers as output?

<html>
<body>

<button onClick="clarity()" style="z-index:1">click for random number in console</button>
    <div id="nachoCheddar01" style="z-index: -1; box-sizing:border-box;border:3px solid green;background-color: blue;position:absolute;top:1%;height:100px;width:200px;">NachoCheddar01</div>
    <div id="nachoCheddar02" style="z-index: -1; box-sizing:border-box;border:3px solid green;background-color: blue;position:absolute;top:20%;height:100px;width:200px;">NachoCheddar02</div>
    <div id="nachoCheddar03" style="z-index: -1; box-sizing:border-box;border:3px solid green;background-color: blue;position:absolute;top:40%;height:100px;width:200px;">NachoCheddar03</div>
    <div id="nachoCheddar04" style="z-index: -1; box-sizing:border-box;border:3px solid green;background-color: blue;position:absolute;top:60%;height:100px;width:200px;">NachoCheddar04</div>
    
</body>

<script>
    var hexBeat;
function clarity() {
  setInterval(function() {
    function randomNumber(min, max) {
      return Math.random() * (max - min) + min;
    }
      
      
      
    hexBeat = randomNumber(100,0);
    if (hexBeat <= 20) {
      console.log(hexBeat);
      document.querySelector("#nachoCheddar01").style.backgroundColor = "green";
      document.querySelector("#nachoCheddar01").style.left = `${document.querySelector("#nachoCheddar01").offsetLeft + 200}px`;
    }
      
     
      
      
      if (hexBeat <= 40 && hexBeat>20) {
      console.log(hexBeat);
      document.querySelector("#nachoCheddar02").style.backgroundColor = "green";
      document.querySelector("#nachoCheddar02").style.left =`${document.querySelector("#nachoCheddar02").offsetLeft + 200}px`;
    }
      
      if (hexBeat <= 60 && hexBeat>40) {
      console.log(hexBeat);
      document.querySelector("#nachoCheddar03").style.backgroundColor = "green";
      document.querySelector("#nachoCheddar03").style.left = `${document.querySelector("#nachoCheddar03").offsetLeft + 200}px`;
          
    if (hexBeat <= 80 && hexBeat>60) {
      console.log(hexBeat);
      document.querySelector("#nachoCheddar04").style.backgroundColor = "green";
      document.querySelector("#nachoCheddar04").style.left = `${document.querySelector("#nachoCheddar04").offsetLeft + 200}px`;
    }
    }
    
  }, 1000)
}
    

                           
    
                      
    
    
</script>
</html>
The fourth div isn't getting any numbers when I put min(1) and max(100) into my random number generator. Any insight as to why the number 1 through 60 will appear in console, and not 60 through 80 would be awesome. It seems that I could place the max in the min parameter and still get the randomness, I have fixed it though at least that far. Bellow is my random number generator in that of what I just referred.
var hexBeat;
function clarity() {
setInterval(function() {
function randomNumber(min, max) {
return Math.random() * (max - min) + min;}
hexBeat = randomNumber(1,100);



Aucun commentaire:

Enregistrer un commentaire