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

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

<body>
  <div id="quote-box"></div>
</body>

              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Josefin+Sans|K2D');

body{
  background: linear-gradient(90deg, lightblue, lightgreen);
  font-family: 'K2D', sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  height: calc(100vh - 100px);
  overflow-y: hidden;
}

.title{
  text-align: center;
  font-weight: 500;
}

#quote-box{
  width: 400px;
  margin: 0 auto;
  padding: 1px 15px;
  font-weight: 550;
  font-size: 22px;
  background: linear-gradient(35deg, #CCFFFF, #FFCCCC);
  text-align: center;
  border-radius: 20px;
  box-shadow: 0px 0px 2px 1px gray;
}

#text{
  margin-block-start: 0.5em;
  margin-block-end: 0.5em;
}

#author{
  margin-block-start: 1em;
  margin-block-end: 1em;
}

#buttons{
  display: flex;
  justify-content: space-between;
}

.twitter-icon{
  color: #1DA1F2;
}

.button{
  font-family: 'K2D', sans-serif;
  font-weight: 500;
  font-size: 1rem;
  padding: 5px;
  border-radius: 50em;
  box-shadow: 0px 0px 3px 0.5px rgb(82, 81, 81);
  border: 0;
  margin-bottom: 10px;
}

.button:focus{
  outline: none;
  border: none;
}

@media only screen and (max-width: 450px){
  .title{
    font-size: 22px;
  }
  #quote-box{
    width: 270px;
  }
}
              
            
!

JS

              
                const Button = (props) => {
  return(
    <div>
      <button className="button" id="new-quote" onClick={props.onClick}>{props.title}</button>    
    </div>
  );
}

const TwitterShare = (props) => {
  return(
    <div>
      <a href={`https://twitter.com/intent/tweet?text= ${props.quote} ${props.author}`} target="_blank" title="Post this quote on Twitter!" id="tweet-quote">
        <i className="fab fa-twitter twitter-icon" >Tweet this</i>
      </a>    
    </div>
  );
}

const Box = (props) => {
  return(
    <div>
      <p id="text">{props.quote}</p>
      <h5 id="author">-{props.author}</h5>
    </div>    
  );
}

/*const WrapTwoComp = () => {
  return(
    <div>
      <TwitterShare quote={quote} author={author}/>
      <Button id="new-quote" title="New Quote" onCLick={getNewQuote}/>
    </div>
  )
}*/

class QuoteBox extends React.Component{
  constructor(props){
    super(props);
    this.state = {
      quote: '',
      author: ''
    }
    this.getQuote = this.getQuote.bind(this);
    this.getNewQuote = this.getNewQuote.bind(this);    
  }  
  componentDidMount() {
    this.getQuote();
  }
  getQuote() {
    let url = 'https://gist.githubusercontent.com/camperbot/5a022b72e96c4c9585c32bf6a75f62d9/raw/e3c6895ce42069f0ee7e991229064f167fe8ccdc/quotes.json'
    axios.get(url).then(res => {
      let data = res.data.quotes
      let quoteNum = Math.floor(Math.random() * data.length)
      let randomQuote = data[quoteNum]
      this.setState({
        quote: randomQuote['quote'],
        author: randomQuote['author']
      })
    })
  }
  getNewQuote() {
    this.getQuote()
  }
  render(){
    return(
      <div>
        <h1 className="title">Random Quote Generator</h1>
        <Box quote={this.state.quote} author={this.state.author} />
        <TwitterShare quote={this.state.quote} author={this.state.author} />
        <Button id="new-quote" title="New Quote" onClick={this.getNewQuote} />
      </div>
      )
  }
}

ReactDOM.render(<QuoteBox />, document.getElementById('quote-box'));
              
            
!
999px

Console