Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container">
			<div class="col-md-6 offset-md-3">
				<h1>Random Number Generator</h1>

				<form id="generatorForm">
					<div class="row">
						<div class="col-md-6">
							<div class="form-group">
								<label for="minNumber">Starting Number</label>
								<input type="number" class="form-control" id="minNumber" aria-describedby="minNumberHelp">
								<small id="minNumberHelp" class="form-text text-muted">Enter the first number of the sequence (i.e., "1")</small>
							</div><!-- .form-group -->
						</div><!-- .col-md-6 -->
						<div class="col-md-6">
							<div class="form-group">
								<label for="maxNumber">Ending Number</label>
								<input type="number" class="form-control" id="maxNumber" aria-describedby="maxNumberHelp">
								<small id="maxNumberHelp" class="form-text text-muted">Enter the last number of the sequence (i.e., "10")</small>
							</div><!-- .form-group -->
						</div><!-- .col-md-6 -->
					</div><!-- .row -->
					
					<div class="row">
						<div class="col-md-12">
							<button type="button" id="generateBtn" class="btn btn-primary" onclick="randomNumber()">Generate Random Number</button>
							
							<button type="reset" id="reset" class="btn btn-secondary">Reset</button>
						</div><!-- .col-md-12 -->
					</div><!-- .row -->
					
					<div class="row">
						<div class="col-md-6 offset-md-3">
							<div class="form-group">
								<label for="result">Random Number</label>
								<input type="number" class="form-control" id="result" aria-describedby="resultHelp" readonly>
								<small id="resultHelp" class="form-text text-muted sr-only">Results are displayed in this box</small>
							</div><!-- .form-group -->
						</div><!-- .col-md-6 -->
					</div><!-- .row -->
				</form>
			</div><!-- .col-md-6 .offset-md-3-->
		</div><!-- .container -->
		
		<!-- Optional JavaScript -->
		<!-- jQuery first, then Popper.js, then Bootstrap JS -->
		<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
		<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
		<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
              
            
!

CSS

              
                body {
	font-family: 'Arial', sans-serif;
}

h1 {
	font-size: 1.5rem;
	font-weight: bold;
	font-family: 'Arial Bold', sans-serif;
	margin: 25px 0;
}

small {
	font-family: 'Arial Narrow', sans-serif;
}

#generateBtn, #reset {
	margin: 25px 5px;
	font-family: 'Arial Narrow', sans-serif;
}

#result {
	height: 4rem;
	font-size: 3rem;
	text-align: center;
	cursor: not-allowed;
}
              
            
!

JS

              
                // TAKE NUMBER INPUT FROM USER "minNumber" and "maxNumber"

// Get "minNumber" from user input and store in variable
// var min = document.getElementById("minNumber").value;

// Get "maxNumber" from user input and store in variable
// var max = document.getElementById("maxNumber").value;

// Use "minNumber" to generate the floor number used in the random calculation
// Use "maxNumber" to generate the ceiling number used in the random calculation

function randomNumber() {
	var min = parseInt(document.getElementById("minNumber").value);
	var max = parseInt(document.getElementById("maxNumber").value) + 1;
	
	if (isNaN(min) || isNaN(max)) {
		alert('Please enter a number into the blank field(s)');
	} else if (min > max) {
		alert('Please make sure the maximum number is greater than the minumum number');
	} else {	
		var result = Math.floor(Math.random() * (max - min)) + min;
		
		document.getElementById("result").value = result;
	}
}

// WHEN 'ENTER' KEY IS PRESSED IN maxNumber FIELD, INVOKE getRequest FUNCTION
document.getElementById('maxNumber').addEventListener("keyup", function(event) {
  event.preventDefault();
  if (event.keyCode === 13) {
    document.getElementById('generateBtn').click();
  }
})

// WHEN 'ENTER' KEY IS PRESSED IN minNumber FIELD, INVOKE getRequest FUNCTION
document.getElementById('minNumber').addEventListener("keyup", function(event) {
  event.preventDefault();
  if (event.keyCode === 13) {
    document.getElementById('generateBtn').click();
  }
})
              
            
!
999px

Console