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

66
Views
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 answers
Answer question

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