【发布时间】:2022-01-20 21:04:09
【问题描述】:
我正在学习编码,目前我被 JavaScript 对象方法所困。如果随机数生成 = 5,我正在尝试编写代码以打印“闪亮”。我该如何实现?此外,它是否打印 undefined ,我不知道它来自哪里。感谢您的阅读。
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());
【问题讨论】:
标签: javascript object math random methods