canvas - Javascript : generate random number function and push into array -
i'm trying push random number of bunnies canvas 1~10 in javascript. however, math.random()
method doesn't seem working. gives me 1 bunny. doing wrong?
var field = []; var randomnum = math.floor(math.random() * 10); field.push(randomnum * new bunny()); function bunny() { ... }
it won't give bunnies @ all. randomnum * new bunny()
nan
1, because you're trying multiply object number.
if want multiple bunnies, have create them, in loop:
var field = []; var randomnum = math.floor(math.random() * 10); (var n = 0; n < randomnum; ++n) { // loop field.push(new bunny()); // creating , pushing } // multiple bunnies function bunny() { // ... }
1 or number, if you've overridden valueof
on bunny.prototype
, seems unlikely.
Comments
Post a Comment