Learn Intermediate OOP by Building a Platformer Game - Step 86

Tell us what’s happening:

I’m struggling to find a callback function that proves that all the items in that array are truthy. I have also tried using:

if(collisionDetectionRules.every((item) => Boolean(item))

and that also didnt work.

Your code so far

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

/* file: styles.css */

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

if(collisionDetectionRules.every(Boolean){
    player.velocity.y = 0;
    return;
  }

// User Editable Region

Your browser information:

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

Challenge Information:

Learn Intermediate OOP by Building a Platformer Game - Step 86

Can you gather some more information?

Try a forEach that logs the result of each Boolean(item) to the console to see what you are dealing with.

I wrote collisionDetectionRules.forEach((item) => console.log(Boolean(item))); both under and on top of the if block in separate occasions and I get ReferenceError: collisionDetectionRules is not defined from the console.
I have also spotted a typo (I missed the closing parenthesis after Boolean) in the code I posted 30 min ago, but that also didn’t pass.

I also resetted the step and rewrote this
collisionDetectionRules.forEach((item) => console.log(Boolean(item)));
hit play and the console started logging an never ending number of true and falses, and it started lagging the browser, so I had to refresh the page. The true and falses were mostly intercalated, with few true true and false false logs.
Am I writing the forEach loop wrong?

This sounds like the desired output to me? Try writing the rest of the function?

I would also ask, what would be the output of this:

console.log(player.position.y + player.height <= platform.position.y)

Which is one of the conditions.

(post deleted by author)

Hi, welcome to the forum :wave:

Please refrain from adding comments to other people’s threads if you aren’t really adding anything.

If you have a question about a challenge please open your own thread

1 Like

So, the browser continuously generates platforms (even when we can’t see them), and compares the position of the player against each of them, right? That’s the reason for the never-ending trues and falses?

I don’t understand. I tried both(item) => Boolean(item) and Boolean(item) inside the .every () and neither passes and give me:

You should have an if statement that uses the every method to check if every rule in the collisionDetectionRules array is truthy.

As per the tests we’re doing, those should work, shouldn’t they?

This also results in a loop of trues and falses, with about 3 falses for each true (without moving the player).

But what does this tell you about your function? If each condition already returns true or false?

There are more instructions than just this, right? Finish writing the function and then see where you are.

I think it means that the every item of the array collisionDetectionRules is truthy, which should be the goal, right?

The only other instruction I can see is that I should add the

player.velocity.y = 0;
    return;
  }

which I did. Am I missing something?

What would the difference be between the outputs of:


console.log(player.position.y + player.height <= platform.position.y)
console.log(Boolean(player.position.y + player.height <= platform.position.y))

no difference.
Now I understand what you wanted to tell me (in a roundabout way, maybe? Maybe I was too absent minded).

I was not understanding your help and ended up looking the answer(a few min ago), and your questions made more sense after. I just needed to fetch the boolean expressions from the array and use the every method to know if ‘everyone was true’. But I still have questions (please, bear with me and help me understand fully). Also, thank you for your patience up until now.

So the Boolean() wasn’t doing anything at all? It was receiving the true or false directly from the array items and reacting like “Oh yeah, true is true. False is false”? I was asking Boolean to turn true and falses into booleans (which would be redundant and unnecessary)?
And the variation of answers (from the console log) was from the position the platforms were spawning in relation to the player. If that’s the case, I still dont understand why Boolean wasn’t working. Also, I still don’t understand what you mean with “write the rest of the function”

2 Likes

Yes, exactly. It wasn’t "wrong"m it was the same result, so just unnecessary.

Just because we were so focused on that part I forgot you had the rest in the original code that you posted, my mistake.

EDIT: And yeah, maybe I was being too obtuse and could have just said that you don’t need the Boolean, but I’m really trying to lead you to the answer yourself. Sometimes it doesn’t work as well as I want

2 Likes