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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <div id="root"></div>
<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>




              
            
!

CSS

              
                #container{
  display:flex;
  align-items:center;
  justify-content:center; 
  padding:5px;
  background-color:red;
  }

#quote-box{
  background-color:white;
  display: grid;
  grid-template-areas:
    "text text text"
    ". . author"
    "media . button";
  }
#quote-box > div{
  padding:5px;
  margin:10px 20px;
}
#text{
  grid-area:text;
}
#author{
  grid-area:author;
}
#tweet-quote{
  grid-area: media;
  margin:10px 10px;
}
#new-quote{
  grid-area:button;
}
.fa {
  padding: 5px;
  font-size: 20px;
  width: 20px;
  height:30px;
  text-align: center;
  text-decoration: none;
  margin: 5px 2px;
}
.fa-twitter {
  background: #55ACEE;
  color: white;
}

#mark{
  width:10px;
}

              
            
!

JS

              
                const quotes=[
  {
    quote: "If you want to shine like a sun, first burn like a sun.",
    author: "A. P. J. Abdul Kalam"
  },
  {
    quote: "Arise! Awake! and stop not until the goal is reached",
    author: "Swami Vivekananda"    
  },
  {
    quote: "Some people don't like change, but you need to embrace change if the alternative is disaster.",
    author: "Elon Musk"
  },
  {
    quote: "Impossible is a word to be found only in the dictionary of fools.",
    author: "Napoleon Bonaparte"
  },
  {
    quote: "If you reveal your secrets to the wind, you should not blame the wind for revealing them to the trees.",
    author: "Khalil Gibran"
  }
];

const randomNum = (frequency) =>(
  Math.floor(Math.random() * frequency)
);

const TEXT = props =>(
  <div id="text"><span id="mark"><strong>''</strong></span>{props.quote}</div>
);

const AUTHOR = props =>{
  return <div id="author"><span>-</span>{props.author}</div>
};

const TWEET = props => {
  return(
    <a id="tweet-quote" href={"https://www.twitter.com/intent/tweet".concat(props.tweet)} className ="fa fa-twitter" target="_blank"></a>  
  );   
};

class Button extends React.Component{
  constructor(props){
    super(props);
    this.handleClick = this.handleClick.bind(this);
  }
  handleClick(){
    this.props.handleNewCode
  };

  render(){
    return(
    <div id="new-quote">
      <button className="btn btn-default" onClick={this.handleClick}>
        {this.props.children}
        </button>
      </div> 
    );
  };
}

class QuoteBox extends React.Component{
  constructor(props){
    super(props);
    this.state ={
      quote: this.props.quote,
      author: this.props.author
    };
   this.handleNewQuote = this.handleNewQuote.bind(this);
  }
  handleNewQuote(){
    //console.log("Click handled by QuoteBox");    
    let index= randomNum(quotes.length);
    do{
      index= randomNum(quotes.length);
    }while (this.state.quote === quotes[index].quote)
      
    this.setState(prevState =>({
      quote: quotes[index].quote,
      author: quotes[index].author
    }));
  };

  render(){
    return (
      <div id="container">
      <div id="quote-box">
        <TEXT quote={this.state.quote} />
        <AUTHOR author={this.state.author} />
        <TWEET tweet={encodeURI("?hashtags=quotes&related=freeCodeCamp&text=".concat(this.state.quote)
            .concat(" ")
            .concat(this.state.author))} />
        <Button handleNewQuote={this.handleNewQuote}>
          New Quote</Button>
      </div>
      </div>
    );
  }
}

class Quotes extends React.Component{
  constructor(props){
    super(props);
  }
  render(){
    return(
      <QuoteBox 
        quote="If you want to shine like a sun, first burn like a sun."
        author= "A. P. J. Abdul Kalam" />
    )
  }
}

ReactDOM.render(<Quotes/>,document.getElementById("root"));
              
            
!
999px

Console