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

              
                <script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
<link href="https://fonts.googleapis.com/css?family=Cantata+One" rel="stylesheet">

<div id="app"></app>
              
            
!

CSS

              
                html, body {
  height: 100%;
  }
  
body {
  background: #999;
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: Helvetica Neue;
  text-align: center;
 }

h1 {
  font-size: 2em;
  display: inline-block;
  margin: 0 auto;
}

#quote-box {

  margin: 1em 0 0 0;
    margin: 0 auto;
  background-color: white;
  max-width: 30em;
  text-color: black;
  text-align: left;
  -webkit-box-shadow: 10px 10px 5px 0px rgba(158,158,158,1);
  -moz-box-shadow: 10px 10px 5px 0px rgba(158,158,158,1);
  box-shadow: 10px 10px 5px 0px rgba(158,158,158,1);
  border: 1px solid black;
}
  
#text {
  font-size: 2.0em;
  font-family: Serif;
  padding: .5em .5em 0 .5em;
}

#author {
  font-size: 1.2em;
  font-family: Serif;
  margin: .5em 0 1em 0;
  padding: 0 .5em 0 .5em;
  text-align: right;
}

button {
   padding: 0 1em 0 1em;
  margin: 0 1em 1em 1em;
  position: relative;
}

#tweet-quote {
  margin: 0 .5em 1em .5em;
  position: relative;
}
              
            
!

JS

              
                //import data from 'https://raw.githubusercontent.com/justinmuskopf/Quotes/master/quotes.json';
//import data from 'https://gist.githubusercontent.com/camperbot/5a022b72e96c4c9585c32bf6a75f62d9/raw/e3c6895ce42069f0ee7e991229064f167fe8ccdc/quotes.json';
class Application extends React.Component {
	constructor(props) {
		super(props);
		this.state = {
			error: null,
			isLoaded: false,
			quotesData: [],
			quotesLength: 0,
			currQuote: "The initial quote will be blank.",
			currAuthor: "The initial author will be blank."
		};
    this.getRandomQuote = this.getRandomQuote.bind(this);
    this.tweetQuote = this.tweetQuote.bind(this);
	}
	componentDidMount() {
		//console.log ("Component Did Mount: ");
		fetch('https://gist.githubusercontent.com/camperbot/5a022b72e96c4c9585c32bf6a75f62d9/raw/e3c6895ce42069f0ee7e991229064f167fe8ccdc/quotes.json').then(response => {
			return response.json();
		}).then(myJson => {
			//console.log (JSON.stringify(myJson))
			myJson = (JSON.stringify(myJson));
			if (typeof myJson === 'string') {
				myJson = JSON.parse(myJson);
				this.setState({
					quotesData: myJson,
					quotesLength: myJson.quotes.length,
					currQuote: "This is the new quote.",
					currAuthor: "This is the new author."
				});
				//console.log ("The array length is: " + this.state.quotesLength);
				//console.log(myJson); //Too much data.
				//console.log(myJson.quotes[1].quote); //This works
				//console.log(myJson.quotes[1].author); //This works
				//console.log(this.state.quotesData); //Too much data.
				//console.log(this.state.currQuote); //This works
				//console.log(this.state.currAuthor); //This works
				this.getRandomQuote();
			} else {
				console.log("Error loading JSON file.")
			}
		});
	}
	getRandomQuote() {
		//console.log ("The array length is: " + this.state.quotesLength);
		var randomNum = Math.floor((Math.random() * this.state.quotesLength) + 1);
		//console.log(randomNum);
		//console.log(this.state.quotesData.quotes[randomNum].quote);
		//console.log(this.state.quotesData.quotes[randomNum].author);
		this.setState({
			currQuote: this.state.quotesData.quotes[randomNum].quote,
			currAuthor: this.state.quotesData.quotes[randomNum].author,
		});   
	}
  
  tweetQuote() {
    //var uri = this.state.currQuote + " - " + this.state.currAuthor;
    //var res = encodeURIComponent(uri);           
    //window.open("https://twitter.com/intent/tweet?hashtags=quotes&related=freecodecamp&text=" + res);
    //return false;
  }
  
	render() {
    var uri = this.state.currQuote + " - " + this.state.currAuthor;
    var res = encodeURIComponent(uri); 
    
    
		//console.log ("Render: ");
		return ( <div id="content">
                <h1>Random Quote Machine</h1>
                <div id="quote-box">
                  <div id="text">“{this.state.currQuote}”</div>
                  <div id="author">-{this.state.currAuthor}</div>
                  <button id="new-quote" onClick={this.getRandomQuote}>New Quote</button>
                  <a id="tweet-quote" href="https://twitter.com/intent/tweet?hashtags=quotes&related=freecodecamp&text=" target="_blank"></a>
                  <a id="tweet-quote2" onClick={this.tweetQuote} href="#">Tweet Quote</a> 
                  
                  <a id="tweet-quote3" href={'https://twitter.com/intent/tweet?hashtags=quotes&related=freecodecamp&text=' + res} target="_blank"> #3</a>
                </div>
            </div> );
	}
}
ReactDOM.render( < Application / > , document.getElementById('app'));
              
            
!
999px

Console