Learn Intermediate OOP by Building a Platformer Game - Step 117

Tell us what’s happening:

Task is to add else if to check if player.position.x in within limits and make it return “You reached a checkpoint!” if it is.What is wrong?

Your code so far

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

/* file: styles.css */

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


      if (index === checkpoints.length - 1) {
        isCheckpointCollisionDetectionActive = false;
        showCheckpointScreen("You reached the final checkpoint!");
        movePlayer("ArrowRight", 0, false)
      }; else if(checkpoint.position.x <=player.position.x<=checkpoint.position.x+40){showCheckpointScreen("You reached a checkpoint!")}


// 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/142.0.0.0 Safari/537.36 Edg/142.0.0.0

Challenge Information:

Learn Intermediate OOP by Building a Platformer Game - Step 117

The red squiggle in the editor means you have a syntax error here

I would look at previous else if statements, such as on line 158.

Also, I would not stick all of your code on one line like that.

I fixed that but it is still not passing.What is wrong?

\`\` if (index === checkpoints.length - 1) {

    isCheckpointCollisionDetectionActive = false;

    showCheckpointScreen("You reached the final checkpoint!");

    movePlayer("ArrowRight", 0, false)

  }else if(checkpoint.position.x <=player.position.x<=checkpoint.position.x+40){showCheckpointScreen("You reached a checkpoint!")}\`\`

I would not put your code all on one line so it’s easier to understand

``else if(checkpoint.position.x <=player.position.x && player.position.x<=checkpoint.position.x+40)

{return showCheckpointScreen(“You reached a checkpoint!”) }``

Still not working

I would still write your code in a way that is easier to read instead of sticking it on as few lines as possible.

      } else if (checkpoint.position.x <= player.position.x && player.position.x<=checkpoint.position.x+40) {
        return showCheckpointScreen("You reached a checkpoint!")
      }

Inside the body of the else if statement, you will need to call the showCheckpointScreen function and pass in the string "You reached a checkpoint!" as an argument.

Are you doing this? It doesn’t seem like it. That return seems questionable.

I don’t fully understand what is wrong with the if condition though.