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

              
                <link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css"/>

<div class="centered well">
<div class="btn-group" role="group" aria-label="...">
  <button type="button" class="btn btn-default btn-select selected-button" id="all">All</button>
  <button type="button" class="btn btn-default" id="online">Online</button>
  <button type="button" class="btn btn-default" id="offline">Offline</button>
</div>
<br>
<div id="createOn" class="togOn left">
</div>
<div id="createOff" class="togOff left">
</div>
</div><!-- /centered -->
              
            
!

CSS

              
                body{
  margin-top: 30px;
  margin-bottom: 30px;
  background: black;
}
.btn-group{
  margin-bottom:10px;
}
.centered {
  width: 300px;
  margin: 0px auto;
  text-align: center;
/*   background: white; */
}
.left {
  width: 100px !important;
  margin: 0px !important;
  text-align: left !important;
/*   background: white; */
}
.small-image{
  width: 100px;
}
.selected-button{
  color:white;
   background: #2093d1;
}

p{
  font-size: 12px !important;
  color: black !important;
}
 
              
            
!

JS

              
                var users = ["freecodecamp", "storbeck", "terakilobyte", "habathcx", "RobotCaleb", "thomasballinger", "noobs2ninjas", "beohoff", "riotgames", "brunofin", "comster404"];


$(function() { //ready short hand

  for (i = 0; i < users.length; i++) {
    (function(i) {
      var user = users[i];

      $.getJSON("https://api.twitch.tv/kraken/streams/" + user + "?callback=?", function(data) {
        if (data.stream == null) { //offline
          $("#createOff").append("<a href='https://www.twitch.tv/" + user + "' target='_blank'><div class='btn well' id='no"+user+"' style='color: red'><h4>" + user + "</h4></div></a><br>");
          if(data.error){
            $("#no"+user).append("<p>No Account</p>");
          }
          
        } else { //online
          $("#createOn").append("<a href='https://www.twitch.tv/" + user + "' target='_blank'><div class='btn well row' style='color: green'><img src='"+data.stream.channel.logo+"' class='small-image'><h4>" + user +"</h4><p>Streaming: "+ data.stream.game+"</p></div></a><br>");
        }

      });
    })(i)
  }
});
$("#all").on("click", function() {
  $("#all").addClass("selected-button");
  $("#online").removeClass("selected-button");
  $("#offline").removeClass("selected-button");
  $("#createOff").show();
  $("#createOn").show();
});
$("#online").on("click", function() {
  $("#online").addClass("selected-button");
  $("#all").removeClass("selected-button");
  $("#offline").removeClass("selected-button");
  $("#createOn").show();
  $("#createOff").hide();
});
$("#offline").on("click", function() {
  $("#offline").addClass("selected-button");
  $("#online").removeClass("selected-button");
  $("#all").removeClass("selected-button");
  $("#createOff").show();
  $("#createOn").hide();
});

/* 
 it's easier to use closures/IIFE. wrap the inside of your forloop in an iIFE, 
using the IIFE will 'lock' the value of your index and the inside of the loop will execute as you'd expect it too
more on the topic for example here: http://benalman.com/news/2010/11/immediately-invoked-function-expression/. (section Saving state with closures)

 you can use promise->https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise or use timeout on the display function */
              
            
!
999px

Console