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

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

CSS

              
                html {
  padding: 0;
  margin: 0;
}

body {
  width: 100vw;
  padding: 0;
  margin: 0;
}

#app {
  padding: 20px;
  width: 100%;
  background-color: whitesmoke;
}

.btn {
  width: 125px;
  height: 35px;
  font-size: 1rem;
}

.btn-increase {
  background-color: transparent;
  color: green;
  border: 1px solid green;
  border-radius: 5px;
}

.btn-increase:hover {
  background-color: green;
  color: white;
}

.btn-decrease {
  background-color: transparent;
  color: orange;
  border: 1px solid orange;
  border-radius: 5px;
}

.btn-decrease:hover {
  background-color: orange;
  color: white;
}

.btn-reset {
  background-color: transparent;
  color: red;
  border: 1px solid red;
  border-radius: 5px;
}

.btn-reset:hover {
  background-color: red;
  color: white;
}

.challenge-text {
  width: 75%;
}
              
            
!

JS

              
                const ChallengeInstructions = () => {
  return(
    <div>
      <p className="challenge-text">In order to get an understanding into how React works, study the code for the above increase button and try to        make sense of what is happening.</p> 
      <strong><p>You will need a comprehensive understanding of JavaScript to be able to implement React.</p></strong>
       <strong><p>Your challenge is to complete the following tasks:</p></strong>
       <ol>
         <li>Implement a "Decrease" button. (The CSS class has been created for you)</li>
         <li>Implement a "Reset" button. (The CSS class has been created for you)</li>
         <li>Randomize the starting number for the clicks. (Hint: Go and Google how componentDidMount works)</li>
         <li>Only display the decrease & reset button when the number of clicks is greater than 0. (Hint: Look at how to use ternary operator)</li>
         <li>Don't show the 's' in times when the number of clicks is 1. (Hint: Again, look at ternary operator)</li>
       </ol>
    </div>
  )
}

// YOUR WORK WILL BE BELOW, DO NOT EDIT ANYTHING ABOVE THIS POINT!!!!!!

class App extends React.Component {
  constructor(){
    super();
    this.state = {
      clicks: 0
    }
  }
  
  increaseClicks = () => {
    this.setState({
      clicks: this.state.clicks + 1
    })  
  }
  
  render(){
   return(
     <div>
      <h1>Simple Clicker App</h1>
       <h2>You have clicked {this.state.clicks} times.</h2>
       <button 
         className="btn btn-increase"
         onClick={() => this.increaseClicks()}
         >Increase</button>
         <ChallengeInstructions />
     </div>
   ) 
  }
}

ReactDOM.render(<App />, document.getElementById('app'))
              
            
!
999px

Console