Ver Mensaje Individual
  #6 (permalink)  
Antiguo 02/04/2015, 17:14
Fattony
 
Fecha de Ingreso: abril-2015
Mensajes: 6
Antigüedad: 9 años, 5 meses
Puntos: 0
Pregunta Respuesta: Atasco con codigo de sorteo

Bueno esto es lo que he averiguado pero por ahora me salen ordenados pero alfabeticamente con el sort, y los quiero ordenar como numeors, lo he intentado con parseInt pero nada.
Y como aclaracion, no uso aleatorio porque las puntuaciones las cojo yo de otra parte y las escribo en las cajas de texto de HTML
Un saludo y gracia spor las respuestas


Código Javascript:
Ver original
  1. var a, a1, b, b2, c, c3, d, d4, e, e5 , f, f6, g, g7, h, h8, i, i9, j, j10, k, k11, l, l12, m, m13, n, n14, o, o15;//aqui son los 30 cuadros de texto, 15 por nombres y 15 por puntuacion
  2. var z;//var para el boton y que dispare la funcion sortear()
  3.  
  4. function inicio()
  5. {
  6.     a = document.getElementById("jugador1");
  7.     a1 = document.getElementById("puntuacion1");
  8.  
  9.     b = document.getElementById("jugador2");
  10.     b2 = document.getElementById("puntuacion2");
  11.  
  12.     c = document.getElementById("jugador3");
  13.     c3 = document.getElementById("puntuacion3");
  14.  
  15.     d = document.getElementById("jugador4");
  16.     d4 = document.getElementById("puntuacion4");
  17.  
  18.     e = document.getElementById("jugador5");
  19.     e5 = document.getElementById("puntuacion5");
  20.  
  21.     f = document.getElementById("jugador6");
  22.     f6 = document.getElementById("puntuacion6");
  23.  
  24.     g = document.getElementById("jugador7");
  25.     g7 = document.getElementById("puntuacion7");
  26.  
  27.     h = document.getElementById("jugador8");
  28.     h8 = document.getElementById("puntuacion8");
  29.  
  30.     i = document.getElementById("jugador9");
  31.     i9 = document.getElementById("puntuacion9");
  32.  
  33.     j = document.getElementById("jugador10");
  34.     j10 = document.getElementById("puntuacion10");
  35.  
  36.     k = document.getElementById("jugador11");
  37.     k11 = document.getElementById("puntuacion11");
  38.  
  39.     l = document.getElementById("jugador12");
  40.     l12 = document.getElementById("puntuacion12");
  41.  
  42.     m = document.getElementById("jugador13");
  43.     m13 = document.getElementById("puntuacion13");
  44.  
  45.     n = document.getElementById("jugador14");
  46.     n14 = document.getElementById("puntuacion14");
  47.  
  48.     o = document.getElementById("jugador15");
  49.     o15 = document.getElementById("puntuacion15");
  50.  
  51.     z = document.getElementById("boton");
  52.     z.addEventListener("click", sortear);
  53.  
  54.  
  55. }
  56.  
  57. function sortear()//y en esta ecuacion me pierdo, pero hice array y empece ciclo
  58. {  
  59.     var puntuaciones = [a1.value , b2.value, c3.value, d4.value, e5.value, f6.value, g7.value, h8.value, i9.value, j10.value, k11.value, l12.value, m13.value, n14.value, o15.value];
  60.     var ganador = document.write(puntuaciones.sort(sortn));
  61.     ganador = parseInt();
  62.     var resultado = puntuaciones[posicion];
  63.     resultado = parseInt();
  64.     var participantes = puntuaciones.length;
  65.     var posicion;
  66.  
  67.     //alert(puntuaciones.sort())
  68.  
  69.     //for(posicion = 0; posicion<= participantes; posicion++)
  70.     //{
  71.         function sortn(x,y)
  72.         {
  73.        
  74.             if(x>y)
  75.             {
  76.                 return -1;
  77.             }
  78.             else if(x == y)
  79.             {
  80.                 return 0;
  81.             }
  82.             else
  83.             {
  84.                 return 1;
  85.             }
  86.         }
  87.         ganador;
  88.     //}