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>

<!-- 

Hello Camper!

For now, the test suite only works in Chrome! Please read the README below in the JS Editor before beginning. Feel free to delete this message once you have read it. Good luck and Happy Coding! 

- The freeCodeCamp Team 

-->
    <title>Random Quote Machine</title>
  <body>

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


    <script type="text/babel" src="javascript.js"></script>
  </body>
              
            
!

CSS

              
                @import 'https://fonts.googleapis.com/css?family=Philosopher|Poiret+One';

//varibales
$authorFontSize : 2rem;
$quoteFontSize : 1.7rem;
$iFontSize: 3rem;
$groundColor: #eee;
$groundColor-mono: #8FB299;
$boxShadow: 4px 4px darken($groundColor,25);

//reset
body{
  background-color:#8FB299 !important;
  margin:0;
  padding:0;
  font-size: 16px;
}

//mixins
@mixin button {
  float: right;
  margin: 1rem;
  font-family: 'Poiret One', cursive;
  font-size: 1.4rem;
  transition: 0.6s;
  border-radius: 0;
  &:hover{
    box-shadow: $boxShadow;
  }
}

@mixin clearFix {
  &:after{
    content: "";
    display: block;
    clear: both;
  }
}

@mixin rotation {
  &:hover{
    animation: rotation 2s linear 1  alternate;
  }
}


//styles
#quote-box{
  background-color: $groundColor;
  max-width: 55rem;
  margin: 10% auto;
  padding: 1rem;
  i{
    font-size: $iFontSize;
    text-align:right;
    color: $groundColor-mono;
    @include rotation;
  }
  .quote-div{
    padding: 1rem;
    p{
      font-size: $quoteFontSize;
      text-align: left;
      font-family: 'Philosopher', sans-serif;

    }
    p#author{
      text-align: center;
      font-weight: normal;
      font-family: 'Poiret One', cursive;
    }
  }
  .btn-div{
    button{
      @include button;
    }
    a{
      @include button;
      text-decoration: none;
      color: white;
    }
    @include clearFix;
  }
}

@keyframes rotation {
  0%{
    transform: rotateZ(0deg);
  }
  50%{
    box-shadow: $boxShadow;
  }
  100%{
    transform: rotateZ(360deg);
  }
}

              
            
!

JS

              
                // !! IMPORTANT README:

// You may add additional external JS and CSS as needed to complete the project, however the current external resource MUST remain in place for the tests to work. BABEL must also be left in place. 

/***********
INSTRUCTIONS:
  - Select the project you would 
    like to complete from the dropdown 
    menu.
  - Click the "RUN TESTS" button to
    run the tests against the blank 
    pen.
  - Click the "TESTS" button to see 
    the individual test cases. 
    (should all be failing at first)
  - Start coding! As you fulfill each
    test case, you will see them go   
    from red to green.
  - As you start to build out your 
    project, when tests are failing, 
    you should get helpful errors 
    along the way!
    ************/

// PLEASE NOTE: Adding global style rules using the * selector, or by adding rules to body {..} or html {..}, or to all elements within body or html, i.e. h1 {..}, has the potential to pollute the test suite's CSS. Try adding: * { color: red }, for a quick example!

// Once you have read the above messages, you can delete all comments. 
const {createStore, combineReducers, applyMiddleware, bindActionCreators } = Redux;
const {Provider, connect } = ReactRedux;
const { Component } = React;
const GETQUOTES = "GETQUOTES";
//const thunk = ReduxThunk.default;

//  JSON endpoint API:
// https://gist.githubusercontent.com/dmakk767/9375ff01aff76f1788aead1df9a66338/raw/491f8c2e91b7d3b8f1c8230e32d9c9bc1a1adfa6/Quotes.json%2520
// quotes json example
/*let quotes = [
{
"quote" : "Life isn’t about getting and having, it’s about giving and being.",
"name": "Kevin Kruse"
},
{
"quote" : "Whatever the mind of man can conceive and believe, it can achieve.",
"name" : "Napoleon Hill"
},
{
"quote" : "Strive not to be a success, but rather to be of value.",
"name" : "Albert Einstein"
},
{
"quote" : "Two roads diverged in a wood, and I—I took the one less traveled by, And that has made all the difference.",
"name" : "Robert Frost"
},
{
"quote" : "I attribute my success to this: I never gave or took any excuse.",
"name" : "Florence Nightingale"
},
{
"quote" : "You miss 100% of the shots you don’t take.",
"name" : "Wayne Gretzky"
},
{
"quote" : "I’ve missed more than 9000 shots in my career. I’ve lost almost 300 games. 26 times I’ve been trusted to take the game winning shot and missed. I’ve failed over and over and over again in my life. And that is why I succeed.",
"name" : "Michael Jordan"
},
{
"quote" : "The most difficult thing is the decision to act, the rest is merely tenacity.",
"name" : "Amelia Earhart"
},
{
"quote" : "Every strike brings me closer to the next home run.",
"name" : "Babe Ruth"
},
{
"quote" : "Definiteness of purpose is the starting point of all achievement.",
"name" : "W. Clement Stone"
}]
*/

// the Redux Store
const initState = {

  quotes: []
}
const reducer = (state = initState , action) => {
  if(action.type === GETQUOTES)
  return {
    ...state,
    quotes: action.quotes
  };
  return state;
};
const store = createStore(reducer);
store.subscribe(()=>{
  console.log("state updated");
  console.log(store.getState());
});
const actionCreator = (quotes) => {
  return{
    type: GETQUOTES,
    quotes
  }
}
// store.dispatch(actionCreator(quotes));
// end of Redux code


// QuoteBox compnonet
class QuoteBox extends Component {
  constructor(props) {
    super(props);
    this.state = {
      currentQuote: "",
      currentAuthor: ""
    }
    this.handleClick = this.handleClick.bind(this);
  }
  handleClick(e){
    if(e.target.getAttribute("id") === "new-quote"){
      let randomNum = Math.floor(Math.random() * this.props.quotes.length);
      let text = document.getElementById("text");
      let author = document.getElementById("author");
      text.innerText = this.props.quotes[randomNum].quote;
      author.innerText = "_"+this.props.quotes[randomNum].name;
      this.setState({
        currentQuote: this.props.quotes[randomNum].quote,
        currentAuthor: this.props.quotes[randomNum].name
      })
    }else if (e.target.getAttribute("id") === "tweet-quote" && this.state.currentQuote === "") {
      this.setState({
        currentQuote: this.props.quotes[0].quote,
        currentAuthor: this.props.quotes[0].name
      })
    }
  }
  componentDidMount(){
    axios.get('https://gist.githubusercontent.com/dmakk767/9375ff01aff76f1788aead1df9a66338/raw/491f8c2e91b7d3b8f1c8230e32d9c9bc1a1adfa6/Quotes.json%2520')
    .then(function(response){
      store.dispatch(actionCreator(response.data));
    })

  }
  compnonetWillUnmount(){
    document.getElementById("new-quote").removeEventListener("click",this.handleClick);
  }
  render(){

    if(this.props.quotes.length){
      return (
        <div id="quote-box" className="container">
          <i className="fas fa-quote-left"></i>
          <div className="quote-div container">
            <p id="text">{this.props.quotes[0].quote}</p>
            <p id="author">_{this.props.quotes[0].name}</p>
          </div>
          <div className="btn-div container">
            <button id="new-quote" className="btn btn-primary" onClick={this.handleClick}>New Quote</button>
            <a id="tweet-quote" className="btn btn-primary" onClick={this.handleClick} href={"https://twitter.com/intent/tweet?hashtags="+this.state.currentAuthor+"&text="+this.state.currentQuote} target="_blank">Tweet Quote</a>
          </div>
        </div>
      )
    }else{
      return(
        <div id="quote-box" className="container">
          <i className="fas fa-quote-left"></i>
          <div className="quote-div container">
            <p id="text">Loading Quotes...</p>
            <p id="author"></p>
          </div>
          <div className="btn-div container">
            <button id="new-quote" className="btn btn-primary">New Quote</button>
            <a id="tweet-quote" className="btn btn-primary">Tweet Quote</a>
          </div>
        </div>
      )
    }
  }
}


const mapStateToProps = (state) => {
  let id = -1;
  return {
    quotes: state.quotes.map(quote => {
      id++;
      return {
        ...quote,
        id: id
      }
    })
  }
}






/* passing my new "Higher Order" connected component to a constant instead of using export default connect()(QuoteBox)*/
const ConnectedQuoteBox = connect(mapStateToProps)(QuoteBox);
/*a compnonet to render my new connected compnonet so I can access redux store*/
class App extends Component{
  constructor(props) {
    super(props)
  }
  render(){
    return(
      <ConnectedQuoteBox />
    )
  }
}
// React.DOM redering
ReactDOM.render(<Provider store={store}><App /></Provider>, document.getElementById('root'));

              
            
!
999px

Console