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
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
Hammad
@newnewb
? what happened?
Marius Nicolae
@bytao7mao
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);



  for (var i = 0; i < 2 ; i++) {
        if (x[i].inv.points > x[i].def.points && c[i]['id'] == x[i].inv['id']) {         
       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();
nested the statement
but doesnt work neither with x[i].inv['id'] or x[i].inv.id
Mois├ęs Man
@moigithub
https://codepen.io/MMan/pen/xPLLKE?editors=1010 @bytao7mao
u need to console.log a lot to see if u accessing the correct object property
Marius Nicolae
@bytao7mao
@moigithub man, you're a saviour ! Thank you so much !
CamperBot
@camperbot
bytao7mao sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3711 | @moigithub |http://www.freecodecamp.org/moigithub
Hammad
@newnewb
@moigithub the hero we need, but not the one we deserve!
Marius Nicolae
@bytao7mao
@newnewb thank you too man for tips
CamperBot
@camperbot
bytao7mao sends brownie points to @newnewb :sparkles: :thumbsup: :sparkles:
:cookie: 293 | @newnewb |http://www.freecodecamp.org/newnewb
Marius Nicolae
@bytao7mao
i'll go to sleep now happy :)) bye seeya and happy coding if you're still staying up
harsh makadia
@harsh-makadia
Is it ok to use objects without double quote?
For Eg- var myObj = { name:"Zed", age:21, car:null };
Dr-D-M
@Dr-D-M
hello dear coders
abraham anak agung
@padunk
@harsh-makadia quote is for string, if it was a number or boolean, you don't need quote
Dr-D-M
@Dr-D-M
can somebody explain me how does the wikipedia APi:opensearch works?
Tom
@moT01
@harsh-makadia you can use single or double quotes for strings - the keys dont need quotes though im pretty sure
Dr-D-M
@Dr-D-M
I need to get the array for it in JSON and the call back, I read through the documentation but, I don't quite get it
Tom
@moT01
so they must be treated as strings be default or something maybe
Dr-D-M
@Dr-D-M
I wanna get the link to make the searcher works
and info from wikipedia, do you know anything about it? how can I get that?