How to jump to the next two-dimensional array value and print this value

Asked

Viewed 42 times

1

I would like to take the value of the second index of the array " game[0][1]=["1", "15/06", "09:00", "Egypt", I have to jump to the next game (next line) until I find a match that hits on the condition of my if...

var atualizacao="10/05/2018 17:03:55";

var rodadaAtual = 1;

var jogo = new Array(7);
jogo[0] = new Array();
jogo[1] = new Array();
jogo[2] = new Array();
jogo[3] = new Array();
jogo[4] = new Array();
jogo[5] = new Array();
jogo[6] = new Array();

//rodada, data, hora, time 1, placar 1, time 2, placar 2

jogo[0][0]=["1", "14/05", "08:00", "Russia", "", "Arabia Saudita", "0"];
jogo[0][1]=["1", "15/06", "09:00", "Egito", "", "Uruguai", ""];
jogo[0][2]=["1", "15/06", "8:00", "Marrocos", "", "Ir�", ""];
jogo[0][3]=["1", "15/06", "15:00", "Portugal", "", "Espanha", ""];
jogo[0][4]=["1", "16/06", "07:00", "Fran�a", "", "Austr�lia", ""];
jogo[0][5]=["1", "16/06", "10:00", "Argentina", "", "Isl�ndia", ""];
jogo[0][6]=["1", "16/06", "13:00", "Peru", "", "Dinamarca", ""];
jogo[0][7]=["1", "16/06", "16:00", "Cro�cia", "", "Nig�ria", ""];
jogo[0][8]=["1", "17/06", "09:00", "Costa Rica", "", "S�rvia", ""];
jogo[0][9]=["1", "17/06", "12:00", "Alemanha", "", "M�xico", ""];
jogo[0][10]=["1", "17/06", "15:00", "Brasil", "", "Su��a", ""];
jogo[0][11]=["1", "18/06", "09:00", "Su�cia", "", "Coreia do Sul", ""];
jogo[0][12]=["1", "18/06", "12:00", "Tun�sia", "", "Inglaterra", ""];
jogo[0][13]=["1", "18/06", "15:00", "B�lgica", "", "Panam�", ""];
jogo[0][14]=["1", "19/06", "09:00", "Col�mbia", "", "Jap�o", ""];
jogo[0][15]=["1", "19/06", "12:00", "Pol�nia", "", "Senegal", ""];

jogo[1][0]=["2", "19/06", "15:00", "R�ssia", "", "Egito", ""];
jogo[1][1]=["2", "20/06", "09:00", "Portugal", "", "Marrocos", ""];
jogo[1][2]=["2", "20/06", "12:00", "Uruguai", "", "Ar�bia Saudita", ""];
jogo[1][3]=["2", "20/06", "15:00", "Ir�", "", "Espanha", ""];
jogo[1][4]=["2", "21/06", "09:00", "Dinamarca", "", "Austr�lia", ""];
jogo[1][5]=["2", "21/06", "12:00", "Fran�a", "", "Peru", ""];
jogo[1][6]=["2", "21/06", "15:00", "Argentina", "", "Cro�cia", ""];
jogo[1][7]=["2", "22/06", "09:00", "Brasil", "", "Costa Rica", ""];
jogo[1][8]=["2", "22/06", "12:00", "Nig�ria", "", "Isl�ndia", ""];
jogo[1][9]=["2", "22/06", "15:00", "S�rvia", "", "Su��a", ""];
jogo[1][10]=["2", "23/06", "09:00", "B�lgica", "", "Tun�sia", ""];
jogo[1][11]=["2", "23/06", "12:00", "Coreia do Sul", "", "M�xico", ""];
jogo[1][12]=["2", "23/06", "15:00", "Alemanha", "", "Su�cia", ""];
jogo[1][13]=["2", "24/06", "09:00", "Inglaterra", "", "Panam�", ""];
jogo[1][14]=["2", "24/06", "12:00", "Jap�o", "", "Senegal", ""];
jogo[1][15]=["2", "24/06", "15:00", "Pol�nia", "", "Col�mbia", ""];

jogo[2][0]=["3", "25/06", "11:00", "Uruguai", "", "R�ssia", ""];
jogo[2][1]=["3", "25/06", "11:00", "Ar�bia Saudita", "", "Egito", ""];
jogo[2][2]=["3", "25/06", "15:00", "Espanha", "", "Marrocos", ""];
jogo[2][3]=["3", "25/06", "15:00", "Ir�", "", "Portugal", ""];
jogo[2][4]=["3", "26/06", "11:00", "Dinamarca", "", "Fran�a", ""];
jogo[2][5]=["3", "26/06", "11:00", "Austr�lia", "", "Peru", ""];
jogo[2][6]=["3", "26/06", "15:00", "Nig�ria", "", "Argentina", ""];
jogo[2][7]=["3", "26/06", "15:00", "Isl�ndia", "", "Cro�cia", ""];
jogo[2][8]=["3", "27/06", "11:00", "M�xico", "", "Su�cia", ""];
jogo[2][9]=["3", "27/06", "11:00", "Coreia do Sul", "", "Alemanha", ""];
jogo[2][10]=["3", "27/06", "15:00", "S�rvia", "", "Brasil", ""];
jogo[2][11]=["3", "27/06", "15:00", "Su��a", "", "Costa Rica", ""];
jogo[2][12]=["3", "28/06", "11:00", "Jap�o", "", "Pol�nia", ""];
jogo[2][13]=["3", "28/06", "11:00", "Senegal", "", "Col�mbia", ""];
jogo[2][14]=["3", "28/06", "15:00", "Panam�", "", "Tun�sia", ""];
jogo[2][15]=["3", "28/06", "15:00", "Inglaterra", "", "B�lgica", ""];

jogo[3][0]=["4", "30/06", "11:00", "1� do grupo C", "", "2� do grupo D", ""];
jogo[3][1]=["4", "30/06", "15:00", "1� do grupo A", "", "2� do grupo B", ""];
jogo[3][2]=["4", "01/07", "11:00", "1� do grupo B", "", "2� do grupo A", ""];
jogo[3][3]=["4", "01/07", "15:00", "1� do grupo D", "", "2� do grupo C", ""];
jogo[3][4]=["4", "02/07", "11:00", "1� do grupo E", "", "2� do grupo F", ""];
jogo[3][5]=["4", "02/07", "15:00", "1� do grupo G", "", "2� do grupo H", ""];
jogo[3][6]=["4", "03/07", "11:00", "1� do grupo F", "", "2� do grupo E", ""];
jogo[3][7]=["4", "03/07", "15:00", "1� do grupo H", "", "2� do grupo G", ""];

jogo[4][0]=["5", "06/07", "11:00", "Vencedor Oitavas 1", "", "Vencedor Oitavas 2", ""];
jogo[4][1]=["5", "06/07", "15:00", "Vencedor Oitavas 3", "", "Vencedor Oitavas 4", ""];
jogo[4][2]=["5", "07/07", "11:00", "Vencedor Oitavas 7", "", "Vencedor Oitavas 8", ""];
jogo[4][3]=["5", "07/07", "15:00", "Vencedor Oitavas 5", "", "Vencedor Oitavas 6", ""];

jogo[5][0]=["6", "10/07", "15:00", "Vencedor Quartas 1", "", "Vencedor Quartas 2", ""];
jogo[5][1]=["6", "11/07", "15:00", "Vencedor Quartas 3", "", "Vencedor Quartas 4", ""];

jogo[6][0]=["7", "14/07", "11:00", "Perdedor Semifinal 1", "", "Perdedor Semifinal 2", ""];
jogo[6][1]=["7", "15/07", "12:00", "Vencedor Semifinal 1", "", "Vencedor Semifinal 2", ""];







function verificarJogo(){                   
            for (i = 0; i < jogo.length; i++) {
                alert("---------------- HORARIO JOGO   "+horaDoJogo,0);
                alert("---------------- DATA DO JOGO  "+dataJogoAtual,0);
                alert("---------------- HORARIO DO SISTEMA  "+hora,0);
                alert("---------------- DATA DO SISTEMA  "+today,0);
                alert("----------------rodadaAtual  "+rodadaAtual,0);   
                alert("----------- primeiro for "+i,0);

                for (j = 0; j < linhas && aux < jogo[rodadaAtual - 1].length; j++) {                        
                    if(today == dataJogoAtual && hora == horaDoJogo){                           
                        alert("----------- entrou no if "+i,0);
                        eval("document.myForm2.strData" + i + ".value='"+ jogo[rodadaAtual - 1][aux][1] + "';");
                        eval("document.myForm2.strHora" + i + ".value='"+ jogo[rodadaAtual - 1][aux][2] + "';");
                        eval("document.myForm2.strTime1_" + i + ".value='"+ jogo[rodadaAtual - 1][aux][3] + "';");
                        eval("document.myForm2.strRes1_" + i + ".value='"+ jogo[rodadaAtual - 1][aux][4] + "';");
                        eval("document.myForm2.separador" + i + ".value='X';");
                        eval("document.myForm2.strRes2_" + i + ".value='"+ jogo[rodadaAtual - 1][aux][6] + "';");
                        eval("document.myForm2.strTime2_" + i + ".value='"+ jogo[rodadaAtual - 1][aux][5] + "';");                          
                        break;

                    }
                    aux++;                      
                }


            }                       

    }
  • Do not use eval for what you are trying to do, as it is unnecessary. As for the question itself it has become half vacant. Do you want to jump to the next game when ? What are the ones you want to show ? You can show an example of what you would expect to see after this code run ?

  • Hello Isac, I would like to do a function that checks within this array which game is compatible with my system date and time. because the way I did , just takes the first line always and is not entering this condition of If

  • What do you mean by compatible ?

  • Compatible would be to enter the IF to print the right value ... I’m learning now to program , sorry

  • What does a "match match match the system date and time" mean to you? Can you give examples of games you think are compatible ? Would games have the same day and the same time, ignoring month, year ? or month and year would also be considered ?

  • For example Isac , today is day 15/05 and are 09:00 in my array has this value in second position Egypt vs Uruguay. . I would like to print it on the screen

  • But your system time is var atualizacao="10/05/2018 17:03:55"; that is 17:03, and how he prints the Uruguay game if he has the time 09:00. I still can’t figure out the exact criteria you want to use to show the games

  • This var update is when the file was generated ,I’m not using it for anything but if you watch the games have all their own dates and times , to catch the time of my system( from my PC. ) I’m giving a getHours() and a getDate() and storing this in a variable to compare with the date and time values of the game .

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.