Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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="randomGenerator">
  <button id="generateInsult"><b>Insult me!</b></button>
  <p id="insult"></p>
</div>
              
            
!

CSS

              
                $pink: #ef3ec9;
.randomGenerator {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  margin-top: 10em;
  font-family: 'Helvetica', 'arial', 'sans-serif';
  color: #3c4859;
  
  #generateInsult {
    text-transform: uppercase;
    padding: 1em 1.25em;
    font-size: 16px;
    background: $pink;
    color: #fff;
    border: 0;
    
    &:hover {
      background: darken($pink, 10%);
      cursor: pointer;
    }
  }
  #insult {
    margin-top: 2em;
    font-size: 20px;
  }
}
              
            
!

JS

              
                
let randomNouns = [
  { plural: ['feet', 'shoes', 'legs', 'arms'] },
  { singular: ['head', 'nose', 'butt', 'face', 'mom', 'dad', 'hair', 'grandma'] }
];

let randomAdjectives = [
  'boring', 
  'dumb', 
  'nasty', 
  'gross', 
  'terrible',
  'stupid',
  'ugly',
  'hairy',
  'useless',
  'sloppy',
  'unnatural',
  'sad', 
  'selfish', 
  'trashy'
];

let randomWords = [
  'horse monster',
  'steamy turd',
  'rat sack',
  'wet goblin',
  'rotten dinosaur',
  'street cow', 
  'fat baby', 
  'hot piece of garbage',
  'pile of eat my shorts',
  'shark snack',
  'turtle fairy',
  'death cult', 
  'vegetable fire', 
  'grouch banana', 
  'wax tampon',
  'turd gobbler', 
  'cotton donkey', 
  'ghost cobra', 
  'jerk-eagle',
  'fart oven', 
  'sneaze basket', 
  'dead hamster',
  'flavor witch',
  'pale bagel'
];


let randomButton = document.getElementById('generateInsult');

let insultText = document.getElementById('insult');
let connector;

function generateInsult() {
  randomButton.addEventListener('click', function(){
    
    let randomNoun = getRandomNoun(randomNouns);
    let randomAdjective = getRandomContent(randomAdjectives);
    let randomWord = getRandomContent(randomWords);
    let connector;
    
    if ( randomAdjective === 'ugly' || randomAdjective === 'unnatural') {
      connector = 'an'; 
    } else {
      connector = 'a';
    }
    
     insultText.innerHTML = 'Your ' + randomNoun + ' like ' + connector + ' ' + randomAdjective + ' ' + randomWord + '.';

    });
  }

generateInsult();


function getRandomContent(randomArray){
  let randomWord = randomArray[Math.floor(Math.random() * randomArray.length)];
  const max = randomArray.length;
  return randomArray[getRandomInt(0, randomArray.length - 1)];  
}


function getRandomNoun(randomNouns) {
  
  let randomIndex = randomNouns[Math.floor(Math.random() * randomNouns.length)];
  let connector; 
  
  if ('plural' in randomIndex) {
    
    connector = 'are'; 
    return randomIndex.plural[Math.floor(Math.random() * randomIndex.plural.length)] + ' ' + connector;
    
  } else if ('singular' in randomIndex ) {
    
    connector = 'is';    
    return randomIndex.singular[Math.floor(Math.random() * randomIndex.singular.length)] + ' ' + connector;
    
  } else {
    
    return;   
  }
}

let getRandomInt = (min, max) => {
    // Create byte array and fill with 1 random number
    let byteArray = new Uint8Array(1);
    window.crypto.getRandomValues(byteArray); 

    let range = max - min + 1;
    let max_range = 256;
    if (byteArray[0] >= Math.floor(max_range / range) * range)
      return getRandomInt(min, max);
    return min + (byteArray[0] % range);
  }
              
            
!
999px

Console