Learn Intermediate OOP by Building a Platformer Game - Step 78

The instructions state:

Step 78

Inside the callback function, create a new const variable called collisionDetectionRules and assign it an empty array.

Inside that array, add a conditional statement that checks if the player’s y position plus the player’s height is less than or equal to the platform’s y position.

Please assist - I have tried the following:

  platforms.forEach((platform) => {
    const collisionDetectionRules = [
      (player.position.y + player.height) <= platform.position.y ? undefined : undefined
    ]
  });

but just get an error:

Sorry, your code does not pass. You're getting there.

You should have a conditional statement that checks if the player's y position plus the player's height is less than or equal to the platform's y position.

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0

Challenge Information:

Learn Intermediate OOP by Building a Platformer Game - Step 78

Hey @ambradnum,

You are very close, but there are just a couple issues here in the code:

  1. You do not need a ternary expression here. You only need the conditional expression. You should remove the entire right side of the ternary so that it is only the condition itself because in these rules, they will evaluate to either true or false based on the condition itself.
  2. The parser in this challenge does not like the parenthesis around: (player.position.y + player.height) so remove the parenthesis surrounding this addition.

After you fix those, you are good to go!

3 Likes

Thank you very much - it works now!