css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

              // Write a function to manipulate the provided string

// 1. Padded Number
// Pad given single numbers in array to look like "10", "05", "16", "02"
const nums = ['2', '4', '25', '10', '3'];
const padNumber = number => (+number < 10) ? `0${number}` : number;
const paddedNum = nums.map(padNumber);

// 2. Camel-to-Title
// Convert a given sentence from camelCase to Title Case
const camelCaseText = "the simplestThings in LIFE are alwaysThe best"

const clean          = text => text.toLowerCase().trim();
const capitalize     = text => `${text[0].toUpperCase()}${text.slice(1)}`;
const splitOnCapital = text => text.replace(/([A-Z])/, (match, capture) => ` ${capture}`);
const noBlanks       = text => !!text

const titleCase = text => {
  return text
    .split(" ")
    .join(' ')
    .split(' ')
    .join(" ")


// 3. Title-to-Camel
// Convert the Title Case back to camelCase
const newTitle = "These Words Should Go In Pairs"
const convertToCamel = text => {
  const words  = text.toLowerCase().split(" ")
  const newArr = []

  // loop over every 2 words and insert as camel_case pair
  for (i = 1; i <= words.length; i += 2) {
    const wordIndex = i - 1;
    const firstWord = words[wordIndex];
    let secondWord  = words[wordIndex + 1];    
    secondWord      = `${secondWord[0].toUpperCase()}${secondWord.slice(1)}` 


  return newArr.join(" ")

// 4. Passage Counter
// How many seconds will it take to read the provided text? 
// If it goes past 60 seconds, quote in minutes!
const passage = `The quick, brown fox jumps over a lazy dog. DJs flock by when MTV ax quiz prog. Junk MTV quiz graced by fox whelps. Bawds jog, flick quartz, vex nymphs. Waltz, bad nymph, for quick jigs vex! Fox nymphs grab quick-jived waltz. Brick quiz whangs jumpy veldt fox. Bright vixens jump; dozy fowl quack. Quick wafting zephyrs vex bold Jim. Quick zephyrs blow, vexing daft Jim. Sex-charged fop blew my junk TV quiz. How quickly daft jumping zebras vex. Two driven jocks help fax my big quiz. Quick, Baz, get my woven flax jodhpurs! "Now fax quiz Jack!" my brave ghost pled. Five quacking zephyrs jolt my wax bed. Flummoxed by job, kvetching W. zaps Iraq. Cozy sphinx waves quart jug of bad milk.`

const timeToRead = text => { 
  const averageReadingTime = 200 // Humans read an average of 200 words per minute
  const cleanedPassage     = passage.split(" ").filter(el => el.trim() !== "")
  const timeInMinutes      = cleanedPassage.length / averageReadingTime;

  return timeInMinutes < 1 
    ? duration = `${Math.round(timeInMinutes * 60)}s` 
    : duration = `${Math.round(timeInMinutes)}mins`

// 5. Pig Latin
// Convert any word to Pig Latin, see how to convert here => https://en.wikipedia.org/wiki/Pig_Latin
const word = "hamlet"
const pigLatin = word => {
  const vowel = /[aeiou]/i;
  const firstVowelIndex = word.indexOf(word.match(vowel)[0]);
  const startsWithVowel = firstVowelIndex === 0;
  return startsWithVowel
    ? `${word}ay`
    : `${word.slice(firstVowelIndex)}${word.substr(0, firstVowelIndex)}ay`;
🕑 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.
Loading ..................