Learn Intermediate OOP by Building a Platformer Game - Step 79

Tell us what’s happening:

if (keys.rightKey.pressed && isCheckpointCollisionDetectionActive) {

platforms.forEach(platform => {
platform.x -= 5;
});
}

What am I doing wrong exactly?

Your code so far

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

/* file: styles.css */

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


    if (keys.rightKey.pressed && isCheckpointCollisionDetectionActive) {
platforms.forEach(platform => {
  platform.x -= 5;
});
    }


// User Editable Region

Your browser information:

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

Challenge Information:

Learn Intermediate OOP by Building a Platformer Game - Step 79
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures-v8/learn-intermediate-oop-by-building-a-platformer-game/step-79`Preformatted text`

Please Tell us what’s happening in your own words.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more you say, the more we can help!

Surround platform with another set of parenthesis, i.e. (platform)

Have you completed this already?

Have you figure out why that’s the case?

No haven’t, but thanks for your input.

Did you implement my suggestion?

platforms.forEach((platform) => {
       ...;
      });

I did and didn’t work, but it’s fine because I can’t fully visualize the concepts in Javascript yet. So for me even what you just sent me looks no different than what I already have.

Did you start this course without attempting the other course prior to it?
I am asking because there is expectations in this one that you have knowledge and understanding of the language which builds upon each other.

In any case, the concept at hand is about arrow function expression:

() => {
  statements
}

As argument passed to the forEach method of the object platforms.

platform does not have a direct property x.
platform has a position which has a property x.

1 Like

I think if you are learning its better if you understand what he was saying was platforms.forEach(platform => {
platform.x -= 5;} over here you should use the parameter since then it would mean that for each would iterate over all the elements of platforms and platform would be the values at any index and then you would have to use the subtraction assignment on it