Learn Intermediate OOP by Building a Platformer Game - Step 84

Tell us what’s happening:

I dont know where the error in this my 3rd boolean expression is coming from?

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region


  platforms.forEach((platform) => {
    const collisionDetectionRules = [
      player.position.y + player.height <= platform.position.y,
      player.position.y + player.height + player.velocity.y >= platform.position.y, player.position.x >= platform.position.x - (player.width / 2)

    ];
  });


// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36

Challenge Information:

Learn Intermediate OOP by Building a Platformer Game - Step 84

you have too many comparison operators.
You only need one comparison operator.
Reset and redo this one.

It’s kind of a bug. You just need to remove the parentheses around the division.

@hbar1st it is two lines of code (elements) because of the comma. But it really should be on separate lines if it was properly formatted.


Edit: just to be clear, it is a regex that is testing the code and it isn’t expecting the parentheses.

assert.match(code, /const\s+collisionDetectionRules\s*=\s*\[\s*player\.position\.y\s*\+\s*player\.height\s*<=\s*platform\.position\.y\s*,\s*player\.position\.y\s*\+\s*player\.height\s*\+\s*player\.velocity\.y\s*>=\s*platform\.position\.y\s*,\s*player\.position\.x\s*>=\s*platform\.position\.x\s*-\s*player\.width\s*\/\s*2\s*,?\s*]\s*;?/);
2 Likes

thanks so much but why are they using regex to test the code?.. now clean code is seen as its wrong causing a bug that someone cannot solve… it can cause headache

those comparisons are required for that stage of the game

It is what it is. A lot of the code is difficult to test “dynamically” because when we do not have access to the running code. There are a few other options, but they often do not work.

But I agree, using regexes is far from ideal.


PR

because you put the code all one line, and I didn’t notice the comma, that’s why my comment was ‘you have too many comparisons’.
But as lasjorg said, that wasn’t the problem. (it was just the way you put all the code on one line that made me think you were trying to use two operators at once)

1 Like

I would definitely suggest you abide by the 80 column rule of formatting (or there about). If the elements in an array take up that much horizontal space, they should be on a new line.

It is just too hard to read when code is allowed to continue so far to the right.

This is how Prettier formats it.

platforms.forEach((platform) => {
  const collisionDetectionRules = [
    player.position.y + player.height <= platform.position.y,
    player.position.y + player.height + player.velocity.y >=
      platform.position.y,
    player.position.x >= platform.position.x - player.width / 2,
  ];
});
1 Like

sorry my bad… the task has be frustrating me

1 Like

sorry my bad… was out of frustration

no need to apologize. It is considered good practice to format your code before posting it online for someone to read, but it is understandable either way.