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
Marius Nicolae
@bytao7mao
what O_o
Hammad
@newnewb
oh sorry i meant tom
Tom
@moT01
countries is an object and the id is used as the key it looks like
so if you found the winner id, and it's 171
you should be able to do something like...
var winningCountry = c[winningID].name
no looping needed
Marius Nicolae
@bytao7mao
but i have so many countries ID's how should i not make it without loops
Hammad
@newnewb
Looping means looking through, from what i understand to pick a winner... you just need to pick one out
Marius Nicolae
@bytao7mao
yeah
Tom
@moT01
cause you have the id(key) you can just pick out the one you need
Marius Nicolae
@bytao7mao
so here "var winningCountry = c[winningID].name" where i should state this and why in winning ID i have to loop through
Hammad
@newnewb
you don't have to loop
Tom
@moT01
i dont know how you're getting the ids - i didn't look through that so i dont know where you need it
put it where you want
whereever you need to get the name of the country
Hammad
@newnewb
okay, @bytao7mao explain your train of thoughts? what are you trying to do exactly? and why do you think you have to loop?
Marius Nicolae
@bytao7mao
i have a big chunk of JSON with Battles and countries objects
inside battles i have defenders(def) and attackers(inv)
with ID's and Points
for each
for countries i have only NAmes and ID's which it corespond to Defenders and Attackers
and i want to compare Points and decide the Winner Country by ID if the ID of the Winner or Loser is EQual to that country
Tom
@moT01
so i think you want to loop through the battle is what you're getting at
Hammad
@newnewb
so, you have a lot of battles? and you want to compare who will win in that battle?
Marius Nicolae
@bytao7mao
yeah, loop through the battles, decide which one has higher ammount of points and return ID of it + country ID
@newnewb yep
and return the ID coresponding to country
Hammad
@newnewb
so first issue is that your loop is set to end at 2? I might wanna set it to be? i < x.length?
Marius Nicolae
@bytao7mao
hmm yeah, i should set it to battles.length right ?
i've set to 2 because i wanted to test only
Hammad
@newnewb
what else are you facing problems with?
I really don't understand this json well, any kind of documentation to it?
Marius Nicolae
@bytao7mao
im testing now the country ID to get it by Object.key but it show me always undefined
i dont know why
i solved it
Hammad
@newnewb
@bytao7mao try sharing the code
oh.. that was fast
Marius Nicolae
@bytao7mao
i solved with the country ID
:|
ok, w8 a moment
var ourRequest = new XMLHttpRequest();
ourRequest.open('GET', "https://www.erepublik.com/en/military/campaigns-new");
ourRequest.onload = function() {
  var x = Object.values(JSON.parse(ourRequest.responseText).battles);

  var c = Object.values(JSON.parse(ourRequest.responseText).countries);

  var c2 = Object.keys(JSON.parse(ourRequest.responseText).countries);


  for (var i = 0; i < 2 ; i++) {
        if (x[i].inv.points > x[i].def.points) {         
       console.log( "winnerID: " + x[i].inv.id  +"Country Winner is: " + c[i]['name'] + " Country KEY id is: " + c[i]['id'] + " Loser ID is:  " + x[i].def.id);

      } else if (x[i].inv.points === x[i].def.points) {
            console.log(" EQUAL" );
      } else {
           console.log("DEF WINS");
       }
  };



};
ourRequest.send();
this return me the following :
winnerID: 79Country Winner is: Romania Country KEY id is: 1 Loser ID is:  167
as you see, the winner id is different from country ID
i need only to make an equality statement and return it
&& c[i]['id'] == x[i].inv.points if i nest this in the if statement it only returns "DEF WINS"
Hammad
@newnewb
aren't you looking for point s vs points? why is your statement id vs points?
Marius Nicolae
@bytao7mao
yeah i should state == x[i].inv.id
but i'm sure it will not work
yep... same