alert("This is a random number generator. It uses the first number you provide as a starting point and the second number as an ending point to create a range for the random number to fall into. If you try any funny business Samuel L. Jackson will get upset.");
var starting_point = parseInt( prompt("Give a starting number.") );
var ending_point = parseInt( prompt("Give an ending point.") );
function getRandomNumber(min, max) {
return Math.floor( Math.random() * (max - min) ) + min;
}
if( isNaN( getRandomNumber(starting_point, ending_point) ) ) {
document.getElementById('print').innerHTML = '<img src="http://www.blogcdn.com/slideshows/images/slides/251/290/0/S2512900/slug/l/samuel-l-jackson-pulp-fiction-1.jpg">';
} else {
document.getElementById('print').innerHTML = "Your random number between " + starting_point + " and " + ending_point + " is " + "<span>" + getRandomNumber(starting_point, ending_point) + "</span>";
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.