Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

63
Visualizações
Show only one item from the array

I have this little Pacman game made in JavaScript

Whats is happening is when i call a random item from the array this is what the game return: Video here

The game show all the items from the array, before display only one of then...

A part of the code

if (gameOver || gameWin) {
//display this array if game win
    text = textOptionsWin[Math.floor(Math.random() * textOptionsWin.length)];;
    if (gameOver) {
    //display this array if game over
      text = textOptions[Math.floor(Math.random() * textOptions.length)];;
      //go back to the first level if lost 
      setTimeout(function () {
        if (tileMap.fase == 1) {
          location.href = "/?fase=1";
          // text = "O COVID-19 TE PEGOU! 😷";
        } else if (tileMap.fase == 2) {
          location.href = "/?fase=1";
        } else if (tileMap.fase == 3) {
          location.href = "/?fase=1";
        } 
      }, 2500);
       //Delay to change the level
    }
}

I'm missing something to this happen? any tip can be useful

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

I don't fully understand, but I think this is the answer:

var a = ["end1", "end2", "end3"]

console.log(a[Math.floor(Math.random() * 3)])

This prints a random item in the array 'a' to console.

about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda