Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

61
Views
Mostrar solo un elemento de la matriz

Tengo este pequeño juego de Pacman hecho en JavaScript.

Lo que sucede es que cuando llamo a un elemento aleatorio de la matriz, esto es lo que devuelve el juego: Video aquí

El juego muestra todos los elementos de la matriz, antes de mostrar solo uno de ellos...

Una parte del código

 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 } }

Me falta algo para que esto suceda? cualquier tip puede ser util

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

No entiendo completamente, pero creo que esta es la respuesta:

 var a = ["end1", "end2", "end3"] console.log(a[Math.floor(Math.random() * 3)])

Esto imprime un elemento aleatorio en la matriz 'a' en la consola.

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!