Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

65
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda