Closed hewinsonj closed 1 year ago
looks like the argument being passed as spotNum may be our culprit here, can you share a console.log() and the code where we evoke that updatePosition2 method
dog.updatePosition2 = function (spotNum) { const diffX = spotNum.x - dog.x; const diffY = spotNum.y - dog.y; if(diffX !== 0 && diffY !== 0){ if(diffX > 0) dog.x += 10; else dog.x -= 10;
if(diffY > 0)
dog.y += 10;
else
dog.y -= 10;
console.log('this is x: ' + dog.x + 'this is y: ' + dog.y)
} else {
dog.x = 40
dog.y = 205
} }
Start Game index.js:270 this is x: 380this is y: 385 index.js:270 this is x: 370this is y: 375 index.js:270 this is x: 360this is y: 365 index.js:270 this is x: 350this is y: 355 index.js:270 this is x: 340this is y: 345 index.js:270 this is x: 330this is y: 335 index.js:270 this is x: 320this is y: 325 index.js:270 this is x: 310this is y: 315 index.js:270 this is x: 300this is y: 305 index.js:270 this is x: 290this is y: 295 index.js:270 this is x: 280this is y: 285 index.js:270 this is x: 270this is y: 275 index.js:270 this is x: 260this is y: 265 index.js:270 this is x: 250this is y: 255 index.js:270 this is x: 240this is y: 245 index.js:270 this is x: 230this is y: 235 index.js:270 this is x: 220this is y: 225 index.js:270 this is x: 210this is y: 215 index.js:270 this is x: 200this is y: 205
all of those are before it jumps to x-40 y-205
Ok, reading that console log made me realize that I needed to change the && to ||, the y coordinate was being satisfied before the x was. Thanks
epic
What's the problem you're trying to solve?
The dog doesn't stop at the position I've designated.
Post any code you think might be relevant (one fenced block per file)