About Annalyn's Infiltration exercise

Hello, all! Happy New Year!!! How are you going? :smiley:

In Task 3, the test unit says it returns ‘true’ when both of them are sleeping.

export function canSignalPrisoner(archerIsAwake, prisonerIsAwake) {
if (!archerIsAwake && prisionerIsAwake) return true;
return false;
}

What am I doing wrong?

You may want to look at the Operator precedence - JavaScript | MDN table, and see that Logical NOT (!) has much higher precedence than Logical AND (&&).

This means that the following are not equivalent:

!(a && b)
// if either a or b, or both are false, this is true
// if a and b are true, this is false

!a && b
// if a is false and b is true, this is true
// if a is true or b is false, this is false

In your example snippet:

if (!archerIsAwake && prisionerIsAwake)

This would read as: if the archer is not awake (asleep) and the prisoner is awake

Actually, I was declaring the consts at the top of the code. That was causing problems with the tests. Thank you.