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

174
Views
How to generate random number and print shiny if equals

I am learning to code and I am currently stuck on JavaScript object methods. I am trying to write a code to print 'shiny' if the random number generates = 5. How can I achieve that? Also, is it printing undefined which I do not know where it is coming from. Thank you for reading.

const pokemonGoCommunityDay = {

  wildEncounters: ['machop','roselia','swablu','gible','snivy','fletchling'],

  currentEncounter() {

    while (this.currentEncounter) {
      this.currentEncounter = this.wildEncounters[Math.floor(Math.random() * 6)];
      console.log(this.currentEncounter);

      if (/* How to make it generate a certain number and if =5 log shiny*/ === 5){
        console.log('Shiny!');
      }break;
    }
  }
}  
console.log(pokemonGoCommunityDay.currentEncounter());
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You already had the necessary piece in your code :)

Here's how you can do it:

if (Math.floor(Math.random() * 6)==5){
  console.log('Shiny!');
}
about 4 years ago · Juan Pablo Isaza 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!