Business Outfitted Bob - Collision Detection

Link to the lesson: Business Outfitted Bob

Working on the Business Bob game, adding in the missing bits of code, and for some reason my collision detection code breaks the entire game (when I hit save, the game disappears from the right side of the window). Removing the code fixes the problem, but I can’t figure out where my code is going wrong:

// Add variables that store the x and y coordinates of the Bob sprite

const bobXCoord = gameState.player.x;

const bobYCoord = gameState.player.y;

// Add code to check collision between Bob and edges of the canvas of the game

if (bobXCoord ← 32 || >= 448) {



if (bobYCoord <=32 || >=568) {



Any help would be appreciated!

Hello, and welcome to the forums!

When something isn’t working the way you expect, it’s always a good idea to check the browser’s console for error messages. In this case, the error messages would likely point you to your if conditions.

These are not valid for a couple of reasons:

if (bobXCoord <- 32 || >= 448) {

if (bobYCoord <=32 || >=568) {

You need to have a value on each side of your comparison operator, so >= number isn’t valid on its own.

if (variable <== 15 || >== 75) { // won't work

if (variable <== 15 || variable >== 75) { // will work

Also, look closely at your code here: bobXCoord <- 32. Do you mean to use <-?

1 Like

Thank you so much for the explanation!
I forgot (or didn’t realise) that I needed the variable on the other side of the ||.
Also, the ← was because I didn’t use the proper way to format code on the forum
Should have been
bobXCoord >= 32

Thank you again for your help!