css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

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

<div id='App'>
</div>
            
          
!
            
              .buttons {
  width: 450px;
  margin: auto;
  display: block;
  .button {
    height: 40px;
    border: none;
    border-radius: 3px;
    color: #fff;
    background: #333;
    outline: none;
    font-size: 0.9rem;
    padding: 8px 15px;
    margin-top: 15px;
    cursor: pointer;
    
    &:hover {
      opacity: 0.9;
    }
  }
}
            
          
!
            
              /*
Improvements
  Change twitter button
  Change new quote button
  Animation between loading colors
*/

const QUOTES = [
  {
    author: "Steve Jobs",
    quote: "Innovation distinguishes between a leader and a follower"
  },
  {
    author: "Bob Iger",
    quote: "The heart and soul of the company is creativity and innovation"
  },
  {
    author: "Winston Churchill",
    quote: "Without tradition, art is a flock of sheep without a shepherd. Without innovation, it is a corpse"
  },
  {
    author: "Linus Torvalds",
    quote: "Talk is cheap. Show me the code"
  },
  {
    author: "John Woods",
    quote: "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live"
  },
  {
    author: "Larry Niven",
    quote: "That's the thing about people who think they hate computers. What they really hate is lousy programmers."
  }
];

const COLORS = ['#16a085', '#27ae60', '#2c3e50', '#f39c12', '#e74c3c', '#9b59b6', '#FB6964', '#342224', "#472E32", "#BDBB99", "#77B1A9", "#73A857", "#1D1E22", "#29335C", "#669BBC", "#3423A6", "#7B6D8D", "#36151E"];

const qStyle = {
  textAlign: 'center',
  fontWeight: '500',
  fontSize: '25px',
  backgroundColor: 'white',
  margin: 'auto',
  maxWidth: '40%',
  padding: '20px',
  borderRadius: '10px',
  position: 'absolute',
  top: '50%',
  left: '50%',
  transform: 'translate(-50%, -50%)',
}

class QuoteMachine extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      text: "Loading...",
      author: " ",
      bg: "#fff"
    }
    this.getNewQuote = this.getNewQuote.bind(this);
  }
  componentDidMount() {
    setTimeout( () => {
      let q = QUOTES[Math.floor(Math.random() * QUOTES.length)];
      let c = COLORS[Math.floor(Math.random() * COLORS.length)];
      this.setState({
        text: q.quote,
        author: q.author,
      });
      document.body.style.background = c;
      document.body.style.color = c;
      document.button.style.color = c;
    }, 750);
  }
  
  getNewQuote = () => {
    let q = QUOTES[Math.floor(Math.random() * QUOTES.length)];
    let c = COLORS[Math.floor(Math.random() * COLORS.length)];
    this.setState({
      text: q.quote,
      author: q.author,
    });
    document.body.style.background = c;
    document.body.style.color = c;
  }
  
  render() {
    return (
      <div id="App">
        <div id="quote-box" style={qStyle}>
          <p id="text">{this.state.text}</p>
          <p id="author">{this.state.author}</p>
          <div className="buttons">
            <a id="tweet-quote" className="button " href="twitter.com/intent/tweet"  title="Tweet this quote!" target="_blank"><i className="fa fa-twitter"></i></a>
            <button id="new-quote" className="button" onClick={this.getNewQuote}>
            New Quote
            </button>
          </div>
        </div>
      </div>
    );
  }
}

ReactDOM.render(<QuoteMachine />, document.getElementById('App'));
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console