Generate Random Whole Numbers with JavaScript Function

generate a random whole number function with test buttons
function randomWholeNum(max) {
  max = max + 1;
  var result_html = document.getElementById("result");
  var random_number = Math.floor(Math.random() * max);
  result_html.innerHTML = random_number;
  return random_number;
}

HTML

<div id='result' class='mb-3 alert alert-primary'>..</div>
<button onclick='randomWholeNum(20);' class='btn btn-primary mb-1'>Generate a Random Number Between 0 - 20</button> <button onclick='randomWholeNum(200);' class='btn btn-primary mb-1'>Generate a Random Number Between 0 - 200</button> <button onclick='randomWholeNum(2000);' class='btn btn-primary mb-1'>Generate a Random Number Between 0 - 2000</button>

Result

..

Other Items in js
Related Search Terms
Page Views

This page has been viewed 377 times.

Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

âĪðŸ‘Đ‍ðŸ’ŧðŸ•đ

Random Quote
Treasure every moment that you have and treasure it more because you shared it with someone special, special enough to spend your time...and remember that time waits for no one.
Unknown