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
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.