The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

JS help

2 posters

Go down

JS help Empty JS help

Post by Anzo 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
Anzo
Forumember

Posts : 365
Reputation : 8
Language : English/Arabic
Location : Baghdad - Iraq

http://www.duelacademy.net/forum

Back to top Go down

JS help Empty Re: JS help

Post by _Twisted_Mods_ 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_
_Twisted_Mods_
Helper
Helper

Male Posts : 2108
Reputation : 336
Language : English
Location : Ms

http://liquidcode.forumotion.com

Back to top Go down

Back to top


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