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 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

              
                .container.my-3.py-5.text-center
  h1.display-1 Romeo Ipsum
  span.lead El generador de texto aleatorio para bachatear contenido en tu página web
  div.my-3
    button.btn.btn-danger Romeízame
    .row.justify-content-center
      .col-7.text-left
        blockquote.blockquote.text-left

              
            
!

CSS

              
                $lightGray: #EEEEEE;
$white: #FFF;
html,body {
  background-color: $lightGray;
}

.container {
  background-color: $white;
}
              
            
!

JS

              
                const romeoSentence = [
  "Como Superman",
  "Trae la toalla porque te vas a mojar",
  "Una aventura es más divertida si huele a peligro",
  "No te hagas la tonta, eso muy bien ya lo sabías",
  "¿Y si te invito a una copa y me acerco a tu boca...?",
  "Son las 5 de la mañana y yo no he dormido nada",
  "Si te parece prudente esta propuesta indecente",
  "Que les perdone Dios, yo no lo pienso hacer",
  "Estoy planeando un secuestro... para robarme tu amor",
  "La baticueva: nuestro nidito de amor",
  "Ya me han informado que tu novio es un insípido aburrido",
  "Me confié de trapecista en un hilito y resbalé por la arrogancia, yo lo admito"
];


const romeoFragment = [
  "Ay chí chí",
  "Llora guitarra... llora",
  "Feels good to be king",
  "El chico de las poesías",
  "¿Te gusta mi bachata mijita?",
  "Yes sir",
  "The king",
  "Maldito sentimiento",
  "Aventura",
  "So nasty",
  "Me quiero morir",
  "Tu grupo favorito mami",
  "You won't forget Romeo",
  "Gostoso",
  "Escucha las palabras"
];

class StringHelper {
  static firstLetterToUpperCase(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
  }

  static firstLetterToLowerCase(string) {
    return string === "Aventura"
      ? string
      : string.charAt(0).toLowerCase() + string.slice(1);
  }
}

class RandomTexts {
  static getElementFromStringCollection(stringCollection) {
    let max = stringCollection.length;
    let index = Math.floor(Math.random() * max);
    return stringCollection[index];
  }
  static getFragment() {
    return RandomTexts.getElementFromStringCollection(romeoFragment);
  }

  static getSentence() {
    return RandomTexts.getElementFromStringCollection(romeoSentence);
  }
}

class ParagraphBuilder {
  static get minElementsPerParagraph() {
    return 3;
  }
  static get maxElementsPerParagraph() {
    return 8;
  }
  static get fragmentBetweenMinSentences() {
    return 1;
  }
  static get fragmentBetweenMaxSentences() {
    return 3;
  }

  static randomizer(min, max) {
    return Math.floor(Math.random() * (max - min) + min);
  }

  static elementsPerParagraph() {
    return ParagraphBuilder.randomizer(
      ParagraphBuilder.minElementsPerParagraph,
      ParagraphBuilder.maxElementsPerParagraph
    );
  }

  static fragmentBetweenNumberOfSentences() {
    return ParagraphBuilder.randomizer(
      ParagraphBuilder.fragmentBetweenMinSentences,
      ParagraphBuilder.fragmentBetweenMaxSentences
    );
  }

  static generateParagraph() {
    let paragraph = "";
    let sentencesSinceLastFragment = 0;
    let fragmentBetweenNumberOfSentences = ParagraphBuilder.fragmentBetweenNumberOfSentences();
    let elementsPerParagraph = ParagraphBuilder.elementsPerParagraph();

    for (var i = 1; i <= elementsPerParagraph; i++) {
      let romeoText = "";
      if (sentencesSinceLastFragment === fragmentBetweenNumberOfSentences) {
        sentencesSinceLastFragment = 0;
        fragmentBetweenNumberOfSentences = ParagraphBuilder.fragmentBetweenNumberOfSentences();
        romeoText = RandomTexts.getFragment();
      } else {
        sentencesSinceLastFragment++;
        romeoText = RandomTexts.getSentence();
      }

      paragraph +=
        1 === i
          ? StringHelper.firstLetterToUpperCase(romeoText)
          : StringHelper.firstLetterToLowerCase(romeoText);

      if (!romeoText.endsWith("?") && !romeoText.endsWith("?")) {
        paragraph += i === elementsPerParagraph ? "." : ",";
      }
      paragraph += i === elementsPerParagraph ? "" : " ";
    }
    return `<p>${paragraph}</p>`;
  }
}

class RomeoIpsum {
  constructor($element, numberOfParagraphs = 3) {
    this.$container = $element;
    this.numberOfParagraphs = numberOfParagraphs;
  }

  render() {
    this.$container.innerHTML = "";
    for (var i = 0; i < this.numberOfParagraphs; i++) {
      this.$container.insertAdjacentHTML(
        "beforeend",
        `<p>${ParagraphBuilder.generateParagraph()}</p>`
      );
    }
  }
}

let romeoIpsum = new RomeoIpsum(
  document.querySelector("blockquote.blockquote"),
  3
);
document
  .querySelector("button")
  .addEventListener("click", () => romeoIpsum.render());

              
            
!
999px

Console