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

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                // 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);
console.log(paddedNum)


// 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(" ")
    .map(splitOnCapital)
    .map(clean)
    .join(' ')
    .split(' ')
    .filter(noBlanks)
    .map(capitalize)
    .join(" ")
}

console.log(titleCase(camelCaseText))


// 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)}` 

    newArr.push(`${firstWord}${secondWord}`);
  } 

  return newArr.join(" ")
}
console.log(convertToCamel(newTitle))

// 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`
}
console.log(timeToRead(passage))

// 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`;
}
console.log(pigLatin(word));
              
            
!
999px

Console