Menu

Question Relates Javascript Could Please Show Random Number Generator Working Function Ret Q43806562

This question relates to Javascript. Could you please show mewhy my random number generator is not working. The function shouldreturn a value between 1-3 and not a 0. Please keep itsimple.

<html>
<head>      
       <title></title>
      
<script>
       var randNum;
      
       randFun();
       /**
       * This function generates a randomnumber between 1-3
       */
       function randFun(){
           randNum =Math.floor(Math.random()*10);
           randNum =Math.round(randNum/3);
              if(randNum !=0){
                  rNum = randNum;
              }
       return rNum;
       }
      
       document.writeln(rNum);
      
</script>
</head>

<body>

</body>
</html>

Expert Answer


Answer to This question relates to Javascript. Could you please show me why my random number generator is not working. The functio…

OR