// Code Generator
function codeGen(a){for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",e=t.slice(0,25),r=t.slice(26,35),h="",o=0;o<a.length;o++)switch(a[o]){case"B":h+=t.charAt(Math.floor(Math.random()*t.length));break;case"C":h+=e.charAt(Math.floor(Math.random()*e.length));break;case"N":h+=r.charAt(Math.floor(Math.random()*r.length));break;default:h+=a[o]}return h}
// Generate first code instantly
$('#generator-code').text( codeGen('BBBB-BBBB-$$$$') );
// Generate more codes by button
$('#generator-button').on('click', function () {
var $this = $(this);
// Disable the button
$this.prop('disabled', true);
// Generate within 1-3 seconds, random time on each click.
var generatorTime = Math.random() * (3 - 1) + 1;
$('#generator-code').fadeOut(function () {
// Show loading
$('#generator-load').fadeIn();
// Random interval to generate new code
setTimeout(function () {
// Hide loading
$('#generator-load').fadeOut(function () {
// Enable the button
$this.prop('disabled', false);
// Generate and show new code
$('#generator-code').fadeIn().text( codeGen('BBBB-BBBB-$$$$') );
});
}, 1000 * generatorTime);
});
});
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.