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.

            
              <html lang="en">
<header>
  <link href='https://fonts.googleapis.com/css?family=Rokkitt' rel='stylesheet' type='text/css'>
  <link href='https://fonts.googleapis.com/css?family=Ubuntu' rel='stylesheet' type='text/css'>
</header>

<body>
  <div class="container-fluid">
    <div class="head">
      <a href="https://codepen.io/amirghafouri/full/pgYyxm/" target="_blank">Amir Ghafouri</a>
      <img src="https://i.ytimg.com/vi/4GsohAElsSE/maxresdefault.jpg" alt="" />
      <div>
       <div class="dropdown">
          <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">select category <span class="caret"></span></button>
          <ul class="dropdown-menu">
            <li class="dropdown-header">Gaming</li>
            <li><a id="cs" href="#">Counter-Strike</a></li>
            <li><a id="fifa" href="#">FIFA 16</a></li>
            <li><a id="league" href="#">League of Legends</a></li>
            <li><a id="poker" href="#">Poker</a></li>
            <li class="divider"></li>
            <li class="dropdown-header">Other</li>
            <li><a id="creative" href="#">Creative</a></li>
            <li><a id="music" href="#">Music</a></li>
            <li class="divider"></li>
            <li><a id="fccFavorites" href="#">freeCodeCamp</a></li>
          </ul>
        </div>
      <i id="infoSymbol" class="fa fa-question"></i>
      </div>
    </div>
    <div id="infoBox" class="hidden">
      <p>Twitch.tv is the world's leading live-streaming video platform for recreational gaming, competitive eSports, and creative content.<br><br> Select a category to see the top active streamers from that category.</p>
    </div>
    <div id="mainContent">
      <div id="streamers" class="">
        <!--
        <div class="media well">
          <div class="media-left">
            <a href="#">
              <img class="media-object" src="http://placehold.it/320x180">
            </a>
          </div>
          <div class="media-body">
            <h4 class="media-heading">freeCodeCamp [<i class="fa fa-circle green"></i>][current viewers: 2779] </h4>
            <p>streaming: JackeL on Twitch API #programming</p>
            <p>subscribers: 420</p>
          </div>
        </div>
        <div class="media">
          <div class="media-left">
            <a href="#">
              <img class="media-object" src="http://placehold.it/140x100" alt="">
            </a>
          </div>
          <div class="media-body">
            <h4>freeCodeCamp [<i class="fa fa-circle"></i>][offline] </h5>
        <p>subscribers: 1940 </p>
        </div>
      </div>
      <div class="media">
        <div class="media-left">
          <a href="#">
            <img class="media-object" src="http://placehold.it/140x100" alt="">
          </a>
        </div>
        <div class="media-body">
          <h4>freeCodeCamp [grey, inactive account] </h5>
        <p>subscribers: 822</p>
        </div>
      </div>
    </div>
  </div>
-->
      </div>
    </div>
</body>

</html>
            
          
!
            
              body {
}

/* HEADER: INFO */
.head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0px 20px;
  margin-left: -15px;
  margin-right: -15px;
  height: 50px;
  color: white;
  background-color: black;

}

.head a {
  color: white;
}
.head img {
  height: inherit;
}
#infoSymbol {
  font-size: 1.8em;
  margin-left: 2px;
  margin-top: 5px;
}

#infoBox {
  border-radius: 10px;
  margin-top: 10px;
  padding: 5px;
  text-align: center;
  color:;
}

/* */

.dropdown {
  display: inline-block;
}



/* mainContent  */

#mainContent {

}

/* #STREAMERS  */

#streamers {
  margin-top: 20px; 
}
.well {
  width: 80%;
  margin-right: auto;
  margin-left: auto;
}
.media {
  background: rgba(250, 250, 250, 1);
  border:;
}
.media:hover {
  background: rgba(163, 26, 255, .2);
}
.media:hover:after {
  background: white;
}
.media-heading {
  font-family: 'Rokkitt', serif; 
  font-size: 2em;
  font-weight: bold;
}
.media-body p {
  font-family: 'Ubuntu', sans-serif;
  font-size: 1.2em;
  font-weight:;
  padding-left: 20px;
}
.media-body i {
  font-size: .7em;
}
.media-object {
  width: 320px;
  height: 180px;
}
.green {
  color: green;
}
.red {
  color: red;
}
.fa-user {
  color: grey;
}
/* SELECT CATEGORY DROPDOWN  */
/* SELECT CATEGORY DROPDOWN  */

            
          
!
            
              // GLOBAL VARIABLES
var fccFavorites = ["freecodecamp", "storbeck", "terakilobyte", "habathcx", "RobotCaleb", "thomasballinger", "noobs2ninjas", "beohoff", "brunofin", "comster404"];

// display info when user puts mouse over question mark 
$("#infoSymbol").on("mouseover", function() {
  $("#infoBox").removeClass("hidden");
});

// hide info when user removes mouse from question mark
$("#infoSymbol").on("mouseout", function() {
  $("#infoBox").addClass("hidden");
});

// TESTING API
fccFavorites.forEach(function(channel) {
  function buildAPICall(type, name) {
    return 'https://api.twitch.tv/kraken/' + type + '/' + name + '?callback=?';
  };
  $.getJSON(buildAPICall("streams", channel), function(data) {
    console.log(data.stream.preview.medium);
  });
});

// MAIN CONTROL
$(document).ready(function() {
  // CS
  $("#cs").on("click", function() {
    $("#streamers").html("");
    $.getJSON('https://api.twitch.tv/kraken/streams?game=Counter-Strike:%20Global%20Offensive&callback=?', function(data) {
      var html = '';
      for (var i = 0; i < 10; i++) {
        html += '<div class="media well"><div class="media-left"><a target="_blank" href="' + data.streams[i].channel.url + '"><img class="media-object" src="' + data.streams[i].preview.medium + '"></a></div><div class="media-body"><h4 class="media-heading">' + data.streams[i].channel.display_name + ' [' + data.streams[i].channel.followers + ' followers][<i class="fa fa-circle green"></i>]</h4><p>current viewers: ' + data.streams[i].viewers + '</p><p>streaming: ' + data.streams[i].channel.status + '</p></div></div>';
      };
      $("#streamers").append(html);
    });
  });

  // FIFA
  $("#fifa").on("click", function() {
    $("#streamers").html("");
    $.getJSON('https://api.twitch.tv/kraken/streams?game=FIFA%2016&callback=?', function(data) {
      var html = '';
      for (var i = 0; i < 10; i++) {
        html += '<div class="media well"><div class="media-left"><a target="_blank" href="' + data.streams[i].channel.url + '"><img class="media-object" src="' + data.streams[i].preview.medium + '"></a></div><div class="media-body"><h4 class="media-heading">' + data.streams[i].channel.display_name + ' [' + data.streams[i].channel.followers + ' followers][<i class="fa fa-circle green"></i>]</h4><p>current viewers: ' + data.streams[i].viewers + '</p><p>streaming: ' + data.streams[i].channel.status + '</p></div></div>';
      };
      $("#streamers").append(html);
    });
  });

  // LEAGUE
  $("#league").on("click", function() {
    $("#streamers").html("");
    $.getJSON('https://api.twitch.tv/kraken/streams?game=League%20of%20Legends&callback=?', function(data) {
      var html = '';
      for (var i = 0; i < 10; i++) {
        html += '<div class="media well"><div class="media-left"><a target="_blank" href="' + data.streams[i].channel.url + '"><img class="media-object" src="' + data.streams[i].preview.medium + '"></a></div><div class="media-body"><h4 class="media-heading">' + data.streams[i].channel.display_name + ' [' + data.streams[i].channel.followers + ' followers][<i class="fa fa-circle green"></i>]</h4><p>current viewers: ' + data.streams[i].viewers + '</p><p>streaming: ' + data.streams[i].channel.status + '</p></div></div>';
      };
      $("#streamers").append(html);
    });
  });

  // POKER
  $("#poker").on("click", function() {
    $("#streamers").html("");
    $.getJSON('https://api.twitch.tv/kraken/streams?game=poker&callback=?', function(data) {
      var html = '';
      for (var i = 0; i < 10; i++) {
        html += '<div class="media well"><div class="media-left"><a target="_blank" href="' + data.streams[i].channel.url + '"><img class="media-object" src="' + data.streams[i].preview.medium + '"></a></div><div class="media-body"><h4 class="media-heading">' + data.streams[i].channel.display_name + ' [' + data.streams[i].channel.followers + ' followers][<i class="fa fa-circle green"></i>]</h4><p>current viewers: ' + data.streams[i].viewers + '</p><p>streaming: ' + data.streams[i].channel.status + '</p></div></div>';
      };
      $("#streamers").append(html);
    });
  });

  // CREATIVE
  $("#creative").on("click", function() {
    $("#streamers").html("");
    $.getJSON('https://api.twitch.tv/kraken/streams?game=creative&callback=?', function(data) {
      var html = '';
      for (var i = 0; i < 10; i++) {
        html += '<div class="media well"><div class="media-left"><a target="_blank" href="' + data.streams[i].channel.url + '"><img class="media-object" src="' + data.streams[i].preview.medium + '"></a></div><div class="media-body"><h4 class="media-heading">' + data.streams[i].channel.display_name + ' [' + data.streams[i].channel.followers + ' followers][<i class="fa fa-circle green"></i>]</h4><p>current viewers: ' + data.streams[i].viewers + '</p><p>streaming: ' + data.streams[i].channel.status + '</p></div></div>';
      };
      $("#streamers").append(html);
    });
  });

  // MUSIC
  $("#music").on("click", function() {
    $("#streamers").html("");
    $.getJSON('https://api.twitch.tv/kraken/streams?game=music&callback=?', function(data) {
      var html = '';
      for (var i = 0; i < 10; i++) {
        html += '<div class="media well"><div class="media-left"><a target="_blank" href="' + data.streams[i].channel.url + '"><img class="media-object" src="' + data.streams[i].preview.medium + '"></a></div><div class="media-body"><h4 class="media-heading">' + data.streams[i].channel.display_name + ' [' + data.streams[i].channel.followers + ' followers][<i class="fa fa-circle green"></i>]</h4><p>current viewers: ' + data.streams[i].viewers + '</p><p>streaming: ' + data.streams[i].channel.status + '</p></div></div>';
      };
      $("#streamers").append(html);
    });
  });

  // FCC FAVORITES
  $("#fccFavorites").on("click", function() {
    $("#streamers").html("");
    fccFavorites.forEach(function(channel) {
      function buildAPICall(type, name) {
        return 'https://api.twitch.tv/kraken/' + type + '/' + name + '?callback=?';
      };
      $.getJSON(buildAPICall("streams", channel), function(data) {
        var status;
        var preview;
        var viewers;
        if (data.stream === null) {
          status = "offline";
          preview = "";
          viewers = status;
        } else if (data.stream === undefined) {
          status = "inactive account";
          preview = "";
          viewers = status;
        } else {
          status = "online";
          preview = data.stream.preview.medium;
          viewers = data.stream.viewers;
        };
        $.getJSON(buildAPICall("channels", channel), function(data) {

          // VARIABLES TO STREAMLINE BUILDING HTML 
          var photo = preview != "" ? preview : /*data.logo != null ? data.logo : */ "http://www-cdn.jtvnw.net/images/twitch_logo3.jpg"; /* concern here about != vs !== to test empty string value of var preview */
          var userName = data.display_name != null ? data.display_name : channel;
          // could use function toReturn(a, b, c) {status === "online" ? a : status === "offline" ? b : c};
          var followers = status === "online" ? data.followers : status === "offline" ? data.followers : "no";
          var isOnline = status === "online" ? "circle green" : status === "offline" ? "circle red" : "user";
          var currentViewers = status === "online" ? 'current viewers: ' + viewers : viewers;
          var streaming = status === "online" ? '<p>streaming: ' + data.status + '</p>' : status === "offline" ? "" : "";

          // BUILD HTML
          var html = '<div class="media well"><div class="media-left"><a target="_blank" href="' + data.url + '"><img class="media-object" src="' + photo + '"></a></div><div class="media-body"><h4 class="media-heading">' + userName + ' [' + followers + ' followers][<i class="fa fa-' + isOnline + '"></i>]</h4><p>' + currentViewers + '</p>' + streaming + '</div></div>';

          // APPLY HTML
          status === "online" ? $("#streamers").prepend(html) : $("#streamers").append(html);
        });
      });
    });
  });
});

/* Q: Is it possible to do a ternary operation within another ternary operation??
var test = 5;
var nike = test < 5 ? "lower" : test > 5 ? "higher" : "equal";
console.log(nike); 
A: Yes, console:"equal"
*/
            
          
!
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