Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <main>

<div id="hero">
	<div class="map">
		<img src="http://i1369.photobucket.com/albums/ag202/philb1900/west-end-map2_zpscpdhgl4e.jpg">	
	</div>
	<div class="headers">
		<h1>West End</h1>
		<h2>Washington, DC</h2>
	</div>
	
</div>
	
<h3>Nearby neighborhoods:</h3>
<p id="change">FOGGY BOTTOM, GEORGETOWN, DUPONT CIRCLE, FARRAGUT SQUARE, KALORAMA HEIGHTS, GOLDEN TRIANGLE, SCOTT CIRCLE
</p>

<button id="caseChangeButton" onclick=triggerCaseChange()>Change to Initial Caps</button>
	
</main>
              
            
!

CSS

              
                /* first, a CSS reset... */

/* https://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
	margin: 0;
	padding: 0;
	border: 0;
	font-size: 100%;
	font: inherit;
	vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
	display: block;
}
body {
	line-height: 1;
}
ol, ul {
	list-style: none;
}
blockquote, q {
	quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
	content: '';
	content: none;
}
table {
	border-collapse: collapse;
	border-spacing: 0;
}



/* my styles below */

body {
	background-color: #eee;
}

main {
	width: 40vw;
	margin: auto;
	margin-top: 3em;
	padding: 2em;
	font-family: "Avenir", "Helvetica", sans-serif;
	border: 1px solid #ccc;
}

h1 {
	font-size: 3em;
}

h2 {
	font-size: 1.5em;
}

h3 {
	font-style: italic;
}

p, h3, button {
	margin-bottom: 0.8em;
}

p {
	line-height: 1.7em;
}

#hero {
	padding-bottom: 1.5em;
	overflow: auto;
}

.headers {
	margin-top: 6em;
}

.map {
	float: right;
}

.map img {
	width: 15em;
}

#caseChangeButton {
	color: white;
	font-size: 1.2em;
	background-color: #c68aa4;
	border: 0px solid white;
	padding: 1em;
	width: 100%;
}


              
            
!

JS

              
                var myParagraph = document.getElementById('change'),
    myParagraphText = myParagraph.innerHTML,
	 myParagraphTextOriginal = [],
    firstArray = myParagraphText.split(', '),
    finalArray = [],
	 myButton = document.getElementById('caseChangeButton'),
    toggle = 0;

myParagraphTextOriginal.push(myParagraphText);

firstArray.forEach(breakItApart);


//this function breaks apart a string but keeps multi-word items together, e.g. Anne Arundel will stay together as one item but two words. Each word can be text-transformed discretely
function breakItApart(item) {

      //define variables including our regex for spaces
      var multiArray = [],
          intermediateArray = [],
          finishedEntry = '',
          reg = /\b\s/;

      //test each item from the first array to see if an individual item has multiple words
      if(reg.test(item) == true) {
        //if so, update our throwaway array containing each word for a multi-word line
        multiArray = item.split(' ');
        for( var i = 0; i < multiArray.length; i++ ) {
          intermediateArray.push(transformIt(multiArray[i]));
        }
        finishedEntry = intermediateArray.join(' ');

      } else {
        //so, if it's not a multi-word item, just transform that one word
        multiArray.push(item);
        finishedEntry = transformIt(multiArray[0]);
      }

      finalArray.push(finishedEntry);
}




function transformIt(entry) {
  var firstChar = entry.charAt(0),
      remainingChars = entry.slice(1),
      newEntry = ((firstChar.toUpperCase()) + (remainingChars.toLowerCase()));

  return newEntry;
}




function triggerCaseChange() {

  if (toggle == 0) {
    myParagraph.innerHTML = finalArray.join(', ');
	 myButton.innerHTML = "Change Back to All Caps";
    toggle = 1;
    console.log(toggle);
  } else {
    myParagraph.innerHTML = myParagraphTextOriginal;
	  myButton.innerHTML = "Change to Initial Caps";
	  toggle = 0;
    console.log(toggle);
  }

}
              
            
!
999px

Console