javascript - Calling function bad argument -


i'm trying write game , got problem function showing player:

function furry() {   this.board=document.queryselectorall('#board div');   this.x = 0;   this.y = 0;   this.direction = "right"; } 

and:

showfurry=function(){   this.x = math.floor(math.random() * 10);   this.y = math.floor(math.random() * 10);   this.board[ this.position(this.furry.x , this.furry.y) ].classlist.add('furry'); } 

and in consol when want call function got this:

uncaught typeerror: cannot read property 'x' of undefined

https://jsfiddle.net/mdx3w24c/

at state after calling function showfurry , showcoin should receive this: enter image description here

try removing functions showfurry , showcoin. then, make function in game class things.

game.prototype.start = function() {     this.board[this.position(this.coin.x, this.coin.y)].classlist.add('coin');     this.board[this.position(this.furry.x, this.furry.y)].classlist.add('furry'); }; 

then when start game, instead of calling showfurry , showcoin can call game.start();

var game = new game(); game.start(); 

also coin constructor set random values x & y, furry construct set them both 0, set them random values in showfurry function. in this fiddle, i've moved constructor.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -