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

              
                <!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css">

<!-- Font Awesome CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<!-- React app root div -->
<div id="root"></div>

<!-- React 17 dev js -->
<script crossorigin src="https://unpkg.com/react@17/umd/react.development.js"></script>

<!-- ReactDOM 17 dev js -->
<script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>

<!-- Bootstrap js -->
<script crossorigin src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js"></script>

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

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Amiri&family=Indie+Flower&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Neucha&display=swap');

/* colors */
$white: #fafafa;
$blue: #58f;
$black: #3f3f3f;

html, body {
  margin: 0;
  padding: 0;
  width: 100vw;
  height: 100vh;
}

#root {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: $blue;
  height: 100vh;
}

#quote-box {
  padding: 2em;
  background-color: $white;
  margin: 20%;
  border-radius: 10px;
  color: $black;

  #text {
    font-family: 'Amiri', serif;
  }
  #author {
    font-family: 'Neucha', cursive;
    font-size: 2.5em;
  }
  .btn-row {
    display: flex;
    flex-direction: row;
    justify-content: flex-end;
    
    #tweet-quote {
      margin-left: 1em;
    }
  }
}
              
            
!

JS

              
                const QuoteBox = (props) => {
  return (
    <div id="quote-box">
      <h1 id="text">
        <i className="fa fa-quote-left"></i> {props.quote}
      </h1>
      <p id="author">- {props.author}</p>
      {props.children}
    </div>
  )
}

const App = () => {
  const [loading, setLoading] = React.useState(true)
  const [quote, setQuote] = React.useState({})
  const [quoteList, setQuoteList] = React.useState([])
  
  const getNewQuote = () => {
    const idx = Math.floor(Math.random() * quoteList.length)
    const newQuote = quoteList[idx]
    setQuote(newQuote)
  }
  
  React.useEffect(() => {
    const fetchData = async () => {
      const quotesURL = 'https://gist.githubusercontent.com/camperbot/5a022b72e96c4c9585c32bf6a75f62d9/raw/e3c6895ce42069f0ee7e991229064f167fe8ccdc/quotes.json'
      const response = await fetch(quotesURL)
      const quotes = await response.json()
      const idx = Math.floor(Math.random() * quotes.quotes.length)
      const newQuote = quotes.quotes[idx]
      setQuoteList(quotes.quotes)
      setQuote(newQuote)
      setLoading(false)
    }
    fetchData()
  }, [])

  if (loading) {
    return <div>loading...</div>
  } else {
    const tweetURL = `https://twitter.com/intent/tweet?hashtags=quotes&related=freecodecamp&text=${quote.quote} --${quote.author}`
    return (
      <QuoteBox quote={quote.quote} author={quote.author}>
        <div className="btn-row">
          <button className="btn btn-primary" id="new-quote" onClick={getNewQuote}>
            New quote
          </button>
          <a 
            id="tweet-quote" 
            href={tweetURL}
            target="_top"
            className="btn btn-secondary"
            >
            <i className="fa fa-twitter"></i> Tweet
          </a>
        </div>
      </QuoteBox>
    )
  }
}

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

Console