JSFiddle - React, Tailwind, and code Playground
HTML
<h1>Simple Random Number Generator</h1>
<h4>Picks a random number in the range of the two numbers you provide.</h4>
<p id="print">
CSS
body {
font: 1.2rem/1.5 "Helvetica Neue", Helvetica, Arial, sans-serif;
}
img {
width: 50%;
box-shadow: 5px 5px 5px;
}
span {
font-size: 40px;
background: orange;
color: red;
font-weight: bold;
padding: 10px;
margin-left: 10px;
}
JavaScript
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>";
}