vendredi 17 décembre 2021

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());



Aucun commentaire:

Enregistrer un commentaire