Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="randomGenerator">
  <button id="generateInsult"><b>Insult me!</b></button>
  <p id="insult"></p>
</div>
            
          
!
            
              $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;
  }
}
            
          
!
            
              
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
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console