所以我在对象内部有一个函数,可以随机选择4个练习之一。
this.lift = function (number, group) {
const random = Math.floor(Math.random() * Math.floor(number));
const pick = group[random]
return pick
}
然后我有与每个组相对应的练习阵列供其选择
this.chest = ["Bench Press", "Incline Bench Press", "Weighted Dips", "Chest Fly"]
this.back = ["Wide Grip Pulldown", "Close Grip Pulldown", "Barbell Row", "Seated/Supported Row"]
etc. etc. etc.
我可以单独调用该函数为每个组选择一个练习,如下所示:
console.log(work.lift(4, work.chest))
console.log(work.lift(4, work.back))
etc. etc.
但这有点丑陋,有时会一次调用该函数24次以上。所以我只想使其运行在一个干净的循环上。所以我有这个:
const arnie = ["chest", "back", "delt", "bicep", "tricep", "quad", "ham", "core"]
for (const muscle of arnie) {
console.log(work.lift(4, whatgoeshere))
}
但是我无法使它正常工作,在循环中使用var i尝试了work.muscle,work.arnie [i],但没有一个运行。我一定很想念一些小东西。那怎么了?