Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Aug 17 09:32
    User @bjorno43 unbanned @linkin-park
  • Jun 20 21:19
    @bjorno43 banned @shenerd140
  • Apr 25 17:13
    @mstellaluna banned @cmal
  • Jan 08 22:05
    @mstellaluna banned @dertiuss323
  • Nov 07 2018 04:42
    User @texas2010 unbanned @ows-ali
  • Nov 02 2018 16:25
    @texas2010 banned @ows-ali
  • Oct 12 2018 05:50
    @bjorno43 banned @NACH74
  • Oct 05 2018 23:02
    @mstellaluna banned @JomoPipi
  • Sep 16 2018 12:21
    @bjorno43 banned @yash-kedia
  • Sep 16 2018 12:16
    @bjorno43 banned @vnikifirov
  • Sep 05 2018 08:12
    User @bjorno43 unbanned @androuino
  • Sep 05 2018 07:38
    @bjorno43 banned @androuino
  • Aug 23 2018 16:57
    User @bjorno43 unbanned @rahuldkjain
  • Aug 23 2018 16:23
    @bjorno43 banned @rahuldkjain
  • Jul 29 2018 14:13
    User @bjorno43 unbanned @jkyereh
  • Jul 29 2018 01:00
    @bjorno43 banned @jkyereh
  • Jul 10 2018 22:09
    @bjorno43 banned @manafn
  • Jul 06 2018 15:20
    @texas2010 banned @imlegend19
  • Jul 03 2018 12:28
    @bjorno43 banned @vbvmatta
  • Jun 29 2018 13:54
    @bjorno43 banned @OGTechnoBoy
Luke
@lhovee
Hey guys, can someone give me some ideas for how to reduce the amount of code I'm using here?
$("#state2").click(function() {
 $.getJSON("https://fcctop100.herokuapp.com/api/fccusers/top/alltime", function(data) {  
   $("#username1").html(data[0].username);
      $("#recent1").html(data[0].recent);
      $("#total1").html(data[0].alltime);
      $("#username2").html(data[1].username);
      $("#recent2").html(data[1].recent);
      $("#total2").html(data[1].alltime);
      $("#username3").html(data[2].username);
      $("#recent3").html(data[2].recent);
      $("#total3").html(data[2].alltime);
      $("#username4").html(data[3].username);
      $("#recent4").html(data[3].recent);
      $("#total4").html(data[3].alltime);
      $("#username5").html(data[4].username);
      $("#recent5").html(data[4].recent);
      $("#total5").html(data[4].alltime);
    });
Rada
@Radascript
@lhovee you can make an array of names and write a function that takes in paramenters "name" and "index" and does this for each name in an array?
Ken Haduch
@khaduch
@lhovee - yes, as @Radascript says, make a function that loops over an array, generates the ID names that you are generating by appending the index value to the strings #username, #recent, and #total - you might also have fixed divs or something in your HTML - you can generate the appropriate number of divs and append them to the DOM in a similar way, using jQuery.
Luke
@lhovee
@Radascript something like this?
var arr = [username1, username2, etc]
for (var i=0; i<arr.length; i++) {$("#arr[i]).html(data[i].username}
@khaduch could you give me a snippet of what that might look like if I was trying to use React to add the appropriate number of divs to the DOM?
kayzon
@quezanw
for the twitch api project is it bad practice to use a for loop instead 'for each' to interate through my array to get the channel name and attach it to the api url?
Ken Haduch
@khaduch
@lhovee - I don't know React at all - I don't know if it would be different there vs. a jQuery example?
Luke
@lhovee
@khaduch no worries, thank you for the help!
CamperBot
@camperbot
lhovee sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 1452 | @khaduch |http://www.freecodecamp.com/khaduch
Luke
@lhovee
@Radascript thank you for the help!
CamperBot
@camperbot
lhovee sends brownie points to @radascript :sparkles: :thumbsup: :sparkles:
:cookie: 367 | @radascript |http://www.freecodecamp.com/radascript
Coy Sanders
@coymeetsworld
@quezanw don't see a problem using either way of looping
Luke
@lhovee
@Radascript @khaduch hey guys, I tried implementing the suggestion you gave me and came up with this. I'm thinking the format of the getJSON and click can't deviate from what the program expects .... ideas?
var arr = [username1, recent1, total1, username2, recent2, total2, username3, recent3, total3, username4, recent4, total4, username5, recent5, total5];
$(document).ready(function() {
  $("#state2").click(function() {
 $.getJSON("https://fcctop100.herokuapp.com/api/fccusers/top/alltime", function(data) {
      for (var i = 0; i < arr.length; i++) {
        if (i == 0 || i == 3 || i == 6 || i == 9 || i == 12) {
          $("#arr[i]").html(data[i].username)
        };
        else if (i == 1 || i == 4 || i == 7 || i == 10 || i == 13) {
          $("#arr[i]").html(data[i].recent)
        };
        else if (i == 2 || i == 5 || i == 8 || i == 11 || i == 14) {
          $("#arr[i]").html(data[i].total)
        };
      };
    });
  });
or maybe I didn't write this very well .... suggestions much appreciated
Coy Sanders
@coymeetsworld
think your semicolons are misplaced @lhovee, i would look into that as a potential issue
Luke
@lhovee
@coymeetsworld okay I will, thank you
CamperBot
@camperbot
lhovee sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star2: 1260 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Coy Sanders
@coymeetsworld
also your jQuery selectors are probably not what you want either
its not going to evaluate i in there, its a String
Luke
@lhovee
@coymeetsworld dang. How can I use jQuery with this array? I'm trying to abbreviate this code:
$("#state1").click(function() {
    $.getJSON("https://fcctop100.herokuapp.com/api/fccusers/top/recent", function(data) {
      $("#username1").html(data[0].username);
      $("#recent1").html(data[0].recent);
      $("#total1").html(data[0].alltime);
      $("#username2").html(data[1].username);
      $("#recent2").html(data[1].recent);
      $("#total2").html(data[1].alltime);
      $("#username3").html(data[2].username);
      $("#recent3").html(data[2].recent);
      $("#total3").html(data[2].alltime);
      $("#username4").html(data[3].username);
      $("#recent4").html(data[3].recent);
      $("#total4").html(data[3].alltime);
      $("#username5").html(data[4].username);
      $("#recent5").html(data[4].recent);
      $("#total5").html(data[4].alltime);
    });
  });
this is supposed to be repeated 100 times and I know writing 300 lines is the wrong answer
Coy Sanders
@coymeetsworld
you can still do that, just saying that "arr[i]" won't evaluate i or arr[i] for you
it will look for the id literally named "arr[i]"
Luke
@lhovee
@coymeetsworld don't I have to leave the "" in the jQuery?
Coy Sanders
@coymeetsworld
no you can put variables in there
the variable will have to be a String I believe
Luke
@lhovee
@coymeetsworld I see! fantastic I appreciate it
Coy Sanders
@coymeetsworld
like for example I have this in my Twitch code:
var iconColumn = $('<div>');
$(iconColumn).appendTo(channelItem);
also have something like this in my Simon code:
$(buttonObj.buttonID).css('background', buttonObj.buttonBG);
buttonObj is a JSON object and buttonID is a String property
Luke
@lhovee
@coymeetsworld I'm closer to something that works I think. Can you take a look at this and see if you can determine why it's not working?
$.getJSON("https://fcctop100.herokuapp.com/api/fccusers/top/alltime", function(data) {
      var arr = ["#username1", "#recent1", "#total1", "#username2", "#recent2", "#total2", "#username3", "#recent3", "#total3", "#username4", "#recent4", "#total4", "#username5", "#recent5", "total5"];
      for (var i = 0; i < arr.length; i++) {
        if (i == 0 || i == 3 || i == 6 || i == 9 || i == 12) {
          $(arr[i]).html(data[i].username);
        } else if (i == 1 || i == 4 || i == 7 || i == 10 || i == 13) {
          $(arr[i]).html(data[i].recent);
        } else if (i == 2 || i == 5 || i == 8 || i == 11 || i == 14) {
          $(arr[i]).html(data[i].total);
        }
      };
    });
  });
Coy Sanders
@coymeetsworld
that can be improved too, but I have another question, why do you need to add these to an id?
unless you're doing something that specifically targets each section that's probably not necessary
maybe just using jQuery's append would be better if you're just listing out users
Luke
@lhovee
@coymeetsworld I'm open to suggestions!
https://codepen.io/lhovee/pen/zBpXXm?editors=1010#0
Coy Sanders
@coymeetsworld
have you done all the Front End projects yet @lhovee?
Pitmation
@Pitmation
I am having issues with jQuery. Can someone give me guidance on how to make my name menu stay on top of page while all other content scrolls beneath it?
Coy Sanders
@coymeetsworld
don't think that's a jQuery issue @Pitmation, you can solve that with CSS if you want to fix the placement of something
max77p
@max77p
@coymeetsworld hey i am having trouble passing a function value into another function
hoping you can help me?
Coy Sanders
@coymeetsworld
which part?
max77p
@max77p
i want to pass the twitchLogo function here into the function below if (data.stream===null)
right now for simplicity sake i just want it to output to console
Pitmation
@Pitmation
@coymeetsworld would I do something like #navBar{

navbar{ position:fixed; background:absolute; z-index:500;

Coy Sanders
@coymeetsworld
@max77p does it matter if the channel is offline or not in order to get the logo? Shouldn't you get it regardless?