javascript - how do i rank the first place -


i need little problem im having rank first person according highest score .

     //variables total value go each person               var must = 0;             var zikt = 0;             var hamt = 0;       // if spacebar pressed      document.body.onkeyup = function(e){         if(e.keycode == 32){            //generate random integers between 1 , 12             var person_0 = math.floor(math.random() * 12 + 1);                   var person_1= math.floor(math.random() * 12 + 1);                   var person_2 = math.floor(math.random() * 12 + 1);                // add total number of pushups             must += person_0;             zikt += person_1;             hamt += person_2;              //displaying total pushups             $("#must .box").html(must);             $("#zikt .box").html(zikt);             $("#hamt .box").html(hamt);              } 

i wanna rank highest number in better way

            //ranking top person              if(must > zikt && hamt){                 $("#first").html("musa: " + must );             } if(zikt > must && hamt){                 $("#first").html("zikria: " + zikt );              } if(hamt > must && zikt){                $("#first").html("hamza: " + hamt );        }  } 

this not work way wrote it

if(must > zikt && hamt){    $("#first").html("musa: " + must ); } if(zikt > must && hamt){    $("#first").html("zikria: " + zikt ); } if(hamt > must && zikt){    $("#first").html("hamza: " + hamt );  

write this:

if(must > zikt && must > hamt){    $("#first").html("musa: " + must ); } else if(zikt > must &&  zikt > hamt){    $("#first").html("zikria: " + zikt ); } else if(hamt > must && hamt > zikt){    $("#first").html("hamza: " + hamt );  

this bad way it. instead of using if else condition try store in array , maximum array.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -