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.

            
              $size: 16px

body 
  font-family: sans-serif

h1
  font-size: $size*2
  text-align: center
  font-weight: 700
  padding-top: 20px
  padding-bottom: 20px

p
  padding: 20px
  text-align: center
  
table
  margin-left: auto
  margin-right: auto
  
td, th 
  padding: 10px
  vertical-align: middle
  font-size: $size
  
  img
    width: 60px
    height: 60px
    
.row 
  border: 1px solid #999
  color: #333
  
.evenRow
  @extend .row
  background-color: #999

.oddRow
  @extend .row
  background-color: white
 
.selected 
  font-weight: 700
  color: gray
  text-decoration: underline
  cursor: pointer

.unselected
  font-weight: 400
  color: black
  text-decoration: underline
  cursor: pointer

#loading
  width: 2*$size
  margin: 50px 0 50px 0
  font-size: 30px
  text-align: center
            
          
!
            
              class App extends React.Component {
  render() {
    return <div>
      <h1>FreeCodeCamp Leaderboard</h1>
      <LeaderBoard />
      <p>Code by <a href="http://lukewalker.org" target="_blank">Luke Walker</a></p>
    </div>
  }                                          
}

class UserRow extends React.Component {
  render() {
    var rank = this.props.index + 1;
    var rowStyle = rank % 2 === 0 ? 'evenRow' : 'oddRow'
    return <tr className={rowStyle} key={rank}><td>{rank}</td><td><img src={this.props.avatar} /></td><td>{this.props.username}</td><td>{this.props.recent}</td><td>{this.props.alltime}</td></tr>;
  }  
}

class LeaderBoard extends React.Component {
  constructor(props) {
    super(props)
    this.state = { users: [], sort: 'Recent', loading: true } 
    this.recent = this.recent.bind(this)
    this.alltime = this.alltime.bind(this)
  }
  componentDidMount() {
    this.recent()
  }
  renderLoading() {
    return <div id="loading">Loading...</div>
  }
  recent() {
    $.get(recent)
    .then(data => this.setState({ users: data, sort: 'Recent', loading: false }))
  }
  alltime() {
    $.get(alltime)
    .then(data => this.setState({ users: data, sort: 'All Time', loading: false }))
  }
  render() {
    var leaderList = this.state.users.map((user, idx) => <UserRow index={idx} avatar={user.img} username={user.username} recent={user.recent} alltime={user.alltime} /> )
    return <table>
      <thead><tr><th>Rank</th><th>Avatar</th><th>Username</th><th onClick={this.recent} className={this.state.sort === 'Recent' ? 'selected' : 'unselected'}>Recent</th><th onClick={this.alltime} className={this.state.sort === 'All Time' ? 'selected' : 'unselected'}>All Time</th></tr></thead>
      <tbody>{ this.state.loading? this.renderLoading() : leaderList }</tbody></table>
  }
}


var recent = "https://fcctop100.herokuapp.com/api/fccusers/top/recent"
var alltime = "https://fcctop100.herokuapp.com/api/fccusers/top/alltime"        
ReactDOM.render(<App />, document.querySelector('#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