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>

<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

<script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v8.0" nonce="rw55s8xv"></script>

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

CSS

              
                @import url("https://fonts.googleapis.com/css2?family=Roboto&display=swap");

body {
  font-family: "Roboto";
}

#quote-box {
  background-color: white;
  margin: 5% 30%;
  padding: 2% 5%;
  top: 15%;
  border-radius: 5px;
  position: absolute;
}

@media screen and (max-width: 1250px) {
  #quote-box {
    background-color: ;
    margin: 5%;
    padding: 5px 8px;
    position: relative;
    top: 5%;
    border-radius: 5px;
    text-align: center;
    display: block;
  }
}

#text {
  color: black;
  text-align: left;
  transition: all 1500ms ease;
}

#author {
  color: black;
  text-align: right;
  transition: all 1500ms ease;
  font-weight: 100;
}

#new-quote {
  color: white;
  margin-left: auto;
  border: none;
  padding: 15px 32px;
  outline: none;
  font-size: 16px;
  border-radius: 5px;
  transition: all 1500ms ease;
}

#new-quote:hover {
  border-radius: 20px;
}

#share {
  display: flex;
  justify-content: align-self;
  outline: none;
  border: none;
}

#backColor {
  position: fixed;
  width: 100%;
  height: 100%;
  z-index: -10;
  text-align: center;
  transition: all 1500ms ease;
  padding: 0;
  margin: 0;
  top: 0;
  left: 0;
}

#share-buttons {
  display: flex;
  flex-direction: column;
}

              
            
!

JS

              
                const theQuotes = [
  {
    quote: "If you have the ability to love, love yourself first.",
    author: 'Charles Bukowski"'
  },
  {
    quote:
      "I don't think that you have any insight whatsoever into your capacity for good until you have some well-developed insight into your capacity for evil.",
    author: "Jordan Peterson"
  },
  {
    quote:
      "This is the real secret of life -- to be completely engaged with what you are doing in the here and now. And instead of calling it work, realize it is play.",
    author: "Alan Watts"
  },
  {
    quote: "The soul becomes dyed with the colour of its thoughts.",
    author: "Marcus Aurelius"
  },
  {
    quote:
      "To be yourself in a world that is constantly trying to make you something else is the greatest accomplishment.",
    author: "Ralph Waldo Emerson"
  },
  {
    quote:
      "If you use more of anything than you need, on the overall scale of things, you are committing a crime against all life.",
    author: "Sadhguru"
  },
  {
    quote:
      "By three methods we may learn wisdom: First, by reflection, which is noblest; Second, by imitation, which is easiest; and third by experience, which is the bitterest.",
    author: "Confucius"
  },
  {
    quote:
      "The cost of sanity in this society, is a certain level of alienation.",
    author: "Terence McKenna"
  },
  {
    quote:
      "Empty your mind, be formless. Shapeless, like water. If you put water into a cup, it becomes the cup. You put water into a bottle and it becomes the bottle. You put it in a teapot, it becomes the teapot. Now, water can flow or it can crash. Be water, my friend.",
    author: "Bruce Lee"
  },
  {
    quote:
      "Rejection is a part of any man’s life. If you can’t accept and move past rejection, or at least use it as writing material – you’re not a real man.",
    author: "Jiraiya"
  }
];

const theColors = [
  "#16a085",
  "#27ae60",
  "#2c3e50",
  "#f39c12",
  "#e74c3c",
  "#9b59b6",
  "#FB6964",
  "#342224",
  "#472E32",
  "#BDBB99"
];

var randomNumber = Math.floor(Math.random() * theQuotes.length);

class MyComponent extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      index: 0
    };
    this.handleClick = this.handleClick.bind(this);
  }

  handleClick() {
    const randomIndex = (currentIndex, size) => {
      const offset = Math.ceil(Math.random() * (size - 1));
      return (currentIndex + offset) % size;
    };

    this.setState({
      index: randomIndex(this.state.index, theQuotes.length)
    });
  }

  render() {
    return (
      <div
        id="backColor"
        style={{ backgroundColor: theColors[this.state.index] }}
      >
        <div id="quote-box">
          <h1 id="text" style={{ color: theColors[this.state.index] }}>
            {"“" + theQuotes[this.state.index].quote}
          </h1>

          <h2 id="author" style={{ color: theColors[this.state.index] }}>
            {"- -" + theQuotes[this.state.index].author}
          </h2>

          <div id="share">
            <div id="share-buttons">
              <a
                target="_blank"
                href="twitter.com/intent/tweet"
                id="tweet-quote"
              >
                <a
                  href="twitter.com/intent/tweet"
                  id="tweet-quote"
                  className="twitter-share-button"
                  data-size="large"
                  data-show-count="false"
                ></a>
              </a>

              <a
                target="_blank"
                data-href="https://codepen.io/aetones/full/yLORqbY"
                className="fb-share-button"
                data-layout="button"
                data-size="large"
              ></a>
            </div>

            <button
              id="new-quote"
              style={{ backgroundColor: theColors[this.state.index] }}
              onClick={this.handleClick}
            >
              New Quote
            </button>
          </div>
        </div>
      </div>
    );
  }
}

ReactDOM.render(<MyComponent />, document.getElementById("root"));

              
            
!
999px

Console