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

              
                <div class="container-fluid">
  
  <div class="jumbotron">
    <h1>freeCodeCamp</h1>
    <h3><em>Use the Twitch.tv JSON API Project</em></h3>
  </div>
  
  <div id="option-bar" class="option-bar">
    <div class="main-item btn btn-warning" id="status-all">ALL</div>
    <div class="main-item btn btn-success" id="status-online">ONLINE</div> 
    <div class="main-item btn btn-danger" id="status-offline">OFFLINE</div>
  </div>

  <div id="show-all">
    <table id="show-all-table" class="table" >
      <thead>
        <tr id="table-header">
          <th class="align-middle">Logo</th>
          <th class="align-middle">Username</th>
          <th class="align-middle">Overview</th>
          <th class="align-middle">Stream Now</th>
        </tr>
      </thead>
      <tbody id="show-all-table-body" class="table-img"></tbody>
    </table>
    
  </div>
  
  <div id="show-online">
    <table id="show-online-table" class="table">
      <thead>
        <tr id="table-header">
          <th class="align-middle">Logo</th>
          <th class="align-middle">Username</th>
          <th class="align-middle">Overview</th>
          <th class="align-middle">Stream Now</th>
        </tr>
      </thead>
      <tbody id="show-online-table-body" class="table-img"></tbody>
    </table>
  </div>
  
  <div id="show-offline">
    <table id="show-offline-table" class="table">
      <thead>
        <tr id="table-header">
          <th class="align-middle">Logo</th>
          <th class="align-middle">Username</th>
          <th class="align-middle">Overview</th>
          <th class="align-middle">Stream Now</th>
        </tr>
      </thead>
      <tbody id="show-offline-table-body" class="table-img"></tbody>
    </table>
  </div>
 </div>
  
  
  
<!--   TODO -->
  
  
<footer><span id="footer-block">Site created & designed by Zhan Hui</span></footer>

  

  
</div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Bubbler+One|Yanone+Kaffeesatz');
h1, h3 {
  text-align: center;
}


.main-item {
  width:33.33333333%;
/*   border: solid #062f63; */
  margin: 2vh;
  text-align: center;
/*   background-color: #89bcff;  */

  
}

.jumbotron {
  background-color: #6c3c84;
  color: white;
}

.option-bar {
  width: 100%;
  margin-bottom: 5vh;
  
  display: flex;
  justify-content: space-around;
}

#show-all {
/*   background-color: #ffff7a; */
  height:100vh;
   display:table;
  margin: auto;
}

#show-online {
  background-color: #42f483;
  height:100vh;
   display:table;
  margin: auto;
}

#show-offline {
  background-color: #f73669;
  height:100vh;
   display:table;
  margin: auto;
}

img {
  width: 15vw;
  border: solid 5px white;
  border-radius: 8vw;
}

/* Display Name */
h4 {
  font-family: 'Yanone Kaffeesatz', sans-serif;
}

/* align for table  */
.table > tbody > tr > td {
  vertical-align: middle;
  
}

#table-header {
  background-color: #242026;
  color: white;
}

th {
   text-align: center;  
   vertical-align: middle;
}

p {
  font-size: 12px;
  font-family: Monospace;
}

#stream-now-col {
  text-align: center;
}

#offline-twitch {
  color: grey;
}

#footer-block {
  background-color: #2d323a;
  color: white;
  display: block;
  position: auto;
  height: 20vh;
  text-align: center;
  font-family: 'Bubbler One', sans-serif;
  padding-top: 5vh;
}

              
            
!

JS

              
                $(document).ready(function(){

  var defaultPageLoad = true;
  
  //when nothing is clicked after page loads, show default to ALL status.
  if (defaultPageLoad) {
    $("#show-all").show();
    $("#show-online").hide();
    $("#show-offline").hide();
  }
  var showBtn = document.querySelector("#status-all");
  
  //ALL btn is clicked
  showBtn.addEventListener( "click", function() {
    $("#show-all").show();
    $("#show-online").hide();
    $("#show-offline").hide();
    defaultPageLoad = false;
  });
  
  //ONLINE btn is clicked
  var onlineBtn = document.querySelector("#status-online");
  
  onlineBtn.addEventListener( "click", function() {
    
    $("#show-online").show();
    $("#show-all").hide();
    $("#show-offline").hide();
    defaultPageLoad = false;
  });
  
  //OFFLINE btn is clicked
  var offlineBtn = document.querySelector("#status-offline");
  
  offlineBtn.addEventListener( "click", function() {
    $("#show-offline").show();
    $("#show-all").hide();
    $("#show-online").hide();
    defaultPageLoad = false;
  });
  
  
  
//TwitchTV clientID: gi51mugvdlvdr5lbfv5ofew3y6eoph
//   Request header (Client-ID: XXXXX)
// Query-string parameter
// (https://api.twitch.tv/kraken/users/44322889?client_id=XXXXX)
  
  
  //Twitch-related 
  
  var streams = ["freecodecamp", "ESL_SC2", "OgamingSC2", "cretetion", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas", "brunofin", "comster404"];
  
  
  //headers' value must be a key-value pair.
  for (var i = 0; i < streams.length; i++) {
    $.ajax ({
      url: 'https://api.twitch.tv/kraken/channels/' + streams[i],
      type: 'GET',
      headers: {'client-ID': 'gi51mugvdlvdr5lbfv5ofew3y6eoph'},
      success: function(dataRetrieved) {
        
        $.getJSON('https://api.twitch.tv/kraken/streams/' + dataRetrieved.name + '?client_id=gi51mugvdlvdr5lbfv5ofew3y6eoph', function(data) {
    if (data.stream != null) {
      
      //Get the detail of stream
      //append all online streams first
      $('#show-all-table-body').append(
        "<tr class='table-success'>" +
          "<td><img src='"+ dataRetrieved.logo + "'></td>" +
          "<td><h4>" + dataRetrieved.display_name + "</h4></td>" +
          "<td><p>" + dataRetrieved.status + "</p></td>" +
          "<td id='stream-now-col'><a target='blank' href='"+ dataRetrieved.url + "'><i class='fa fa-twitch' aria-hidden='true'></i></a></td>" +
        "</tr>"
      );
      
      $('#show-online-table-body').append(
        "<tr class='table-success'>" +
          "<td><img src='"+ dataRetrieved.logo + "'></td>" +
          "<td><h4>" + dataRetrieved.display_name + "</h4></td>" +
          "<td><p>" + dataRetrieved.status + "</p></td>" + 
          "<td id='stream-now-col'><a target='blank' href='"+ dataRetrieved.url + "'><i class='fa fa-twitch' aria-hidden='true'></i></a></td>" +
        "</tr>"
      );
      
  } else {
     //TODO add action if stream is not offline
       $('#show-all-table-body').append(
        "<tr class='table-danger'>" +
          "<td><img src='"+ dataRetrieved.logo + "'></td>" +
          "<td><h4>" + dataRetrieved.display_name + "</h4></td>" +
          "<td><p>" + dataRetrieved.status + "</p></td>" +
          "<td id='stream-now-col'><a target='blank' href='"+ dataRetrieved.url + "'><i class='fa fa-twitch' id='offline-twitch' aria-hidden='true'></i></a></td>" +
        "</tr>"
        );
    
        $('#show-offline-table-body').append(
        "<tr class='table-danger'>" +
          "<td><img src='"+ dataRetrieved.logo + "'></td>" +
          "<td><h4>" + dataRetrieved.display_name + "</h4></td>" +
          "<td><p>" + dataRetrieved.status + "</p></td>" + 
          "<td id='stream-now-col'><a target='blank' href='"+ dataRetrieved.url + "'><i class='fa fa-twitch' id='offline-twitch' aria-hidden='true'></i></a></td>" +
        "</tr>"  
      );
  }});
        
      },
      error: function(err) { 
        //TODO insert action for non-existent user
        $('#show-all-table-body').append(
        "<tr class='table-active'>" +
          "<td><img/></td>" +
          "<td><h4>" + err.responseJSON.message + "</h4></td>" +
          "<td><p>" + "Twitch account might be closed or never existed." + "</p></td>" +
          "<td id='stream-now-col'><i class='fa fa-exclamation-circle' aria-hidden='true'></i></td>" +
        "</tr>"
      );
      }
    });
   };
  
});
              
            
!
999px

Console