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?
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).
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”
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