The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

JS help

View previous topic View next topic Go down

JS help

Post by Anzo on October 29th 2014, 5:35 pm

Hello,

I don't know how JavaScript works, I can only work on HTML and CSS, hence I require some help with this particular JS.

We have a table where we rank people according to their wins/loss + points. In this table, each win is +1 point and each loss is -1 point (i think).

I believe this is the part that handles math in this code:
Code:
    function bubbleSort(a)
    {
        var swapped;
        do {
            swapped = false;
            for (var i=0; i < a.length-1; i++) {
                if (eval(a[i][5]) < eval(a[i+1][5])) {
                    var temp = a[i];
                    a[i] = a[i+1];
                    a[i+1] = temp;
                    swapped = true;
                }
            if (eval(a[i][5]) == eval(a[i+1][5])) {
                if (eval(a[i][3]) > eval(a[i+1][3])) {
                  var temp = a[i];
                  a[i] = a[i+1];
                  a[i+1] = temp;
                  swapped = true;
                }
                }
            }
        } while (swapped);
    }


I could be wrong tho.

Anyway, this is the page, if you want to take a look: http://www.duelacademy.net/h1-rankings

I'd like it to count each win as +3 points, and each loss as -1 point. There is Wins, Lose, Games Played, Points. I'm not sure how the code works exactly, but It uses your wins, loses and games played to do the math and distribute points.

I can't explain this any better lol

Thanks for your help Very Happy

Anzo
Forumember

Posts : 303
Reputation : 6
Language : English/Arabic
Location : Baghdad - Iraq

http://www.duelacademy.net/forum

Back to top Go down

Re: JS help

Post by _Twisted_Mods_ on October 29th 2014, 6:16 pm

the way its calculated you would have to add 3 wins for every 1 win

one of these should do the trick




Code:
function bubbleSort(a)
{
var swapped;
do {
swapped = false;
for (var i=0; i < a.length-1; i++) {
if (eval(a[i][5]) < eval(a[i+3][5])) {
var temp = a[i];
a[i] = a[i+3];
a[i+3] = temp;
swapped = true;
}
if (eval(a[i][5]) == eval(a[i+1][5])) {
if (eval(a[i][3]) > eval(a[i+1][3])) {
var temp = a[i];
a[i] = a[i+1];
a[i+1] = temp;
swapped = true;
}
}
}
} while (swapped);
}

or

Code:
  function bubbleSort(a)
  {
  var swapped;
  do {
  swapped = false;
  for (var i=0; i < a.length-1; i++) {
  if (eval(a[i][5]) < eval(a[i+1][5])) {
  var temp = a[i];
  a[i] = a[i+1];
  a[i+1] = temp;
  swapped = true;
  }
  if (eval(a[i][5]) == eval(a[i+1][5])) {
  if (eval(a[i][3]) > eval(a[i+3][3])) {
  var temp = a[i];
  a[i] = a[i+3];
  a[i+3] = temp;
  swapped = true;
  }
  }
  }
  } while (swapped);
  }


_Twisted_Mods_
Helper
Helper

Male Posts : 2020
Reputation : 299
Language : English
Location : Ms

http://liquidcode.forumotion.com

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum