I cannot pass this final code 117

function checkCollision(player, checkpoint) {
return player.position.x >= checkpoint.position.x &&
player.position.x <= checkpoint.position.x + 40;
}

function handleCheckpointCollision(player, checkpoint, index, checkpoints) {
if (index === checkpoints.length - 1) {
isCheckpointCollisionDetectionActive = false;
showCheckpointScreen(“You reached the final checkpoint!”);
movePlayer(“ArrowRight”, 0, false);
} else if (checkCollision(player, checkpoint)) {
showCheckpointScreen(“You reached a checkpoint!”);
}
}

// Example usage
const player = { position: { x: 50 } };
const checkpoints = [
{ position: { x: 30 } },
{ position: { x: 70 } },
// Add more checkpoints as needed
];

checkpoints.forEach((checkpoint, index) => {
handleCheckpointCollision(player, checkpoint, index, checkpoints);
});

Please provide more information and a link to the challenge you are working on.

[

Learn Intermediate OOP by Building a Platformer Game - Step 117](Learn Intermediate OOP by Building a Platformer Game - Step 117)

JavaScript

1

/

5

emrua

Apr 22

Tell us what’s happening:

hello! I dont understand why my code isn’t correct

Your code so far

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

/* file: styles.css */

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

    }else if (
    player.position.x >= 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/123.0.0.0 Safari/537.36

Challenge Information:

Learn Intermediate OOP by Building a Platformer Game - Step 117

freecodecamp.org

freeCodeCamp.org

Learn to Code — For Free

This is my code so far function checkCollision(player, checkpoint) {
return player.position.x >= checkpoint.position.x &&
player.position.x <= checkpoint.position.x + 40;
}

function handleCheckpointCollision(player, checkpoint, index, checkpoints) {
if (index === checkpoints.length - 1) {
isCheckpointCollisionDetectionActive = false;
showCheckpointScreen(“You reached the final checkpoint!”);
movePlayer(“ArrowRight”, 0, false);
} else if (checkCollision(player, checkpoint)) {
showCheckpointScreen(“You reached a checkpoint!”);
}
}

// Example usage
const player = { position: { x: 50 } };
const checkpoints = [
{ position: { x: 30 } },
{ position: { x: 70 } },
// Add more checkpoints as needed
];

checkpoints.forEach((checkpoint, index) => {
handleCheckpointCollision(player, checkpoint, index, checkpoints);
});

This code of yours is correct.

Try to reset the step and do it again.
If it’s still not passed, try reset the cache browser, turn off all extensions, or try another browser.