Is there anything wrong with my code?

Is there anything wrong with my code? I can’t find it, anybody can help me with this?

Question as followed:

Boo who

Check if a value is classified as a boolean primitive. Return true or false .
Boolean primitives are true and false .

  **Your code so far**

function booWho(bool) {
if (bool === true || false){
return true;
}
return false;
}

booWho(null);
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36

Challenge: Boo who

Link to the challenge:

You just need to make a check if bool is equal to true or not. No need to specify an array with true and false and then check in it.
You should directly use the == or === (strict type check is even better) operator to check if bool is true or false.

I’ve tried like the following , but it doesn’t work, could you tell me what is wrong?

function booWho(bool) {
if (bool === true || false){
return true;
}
return false;
}

booWho(null);

Remove || false from the condition. It should return true only if bool === true || bool === false. Else if bool is neither true nor false, it should return false. So after the if part, you need an else part which returns false. Coz both these are mutually exclusive.

What the question means is to check a value isa boolean primitive which contains “true” and “false”. if I remove || false, it turns out “false” where should be “true”. I hope I’ve made me clear.

I have edited my previous reply. Please check.

So the code should go something like this:

if (bool === true || bool === false)
{ then you return true here}
else
{ you return false}

That’s it!

1 Like

Wow! Great! Amazing! Thanks!

For an Explanation:

Your if statement condition said:

If bool is equal to true, evaluate to true, OR evaluate to false.

… and as you know, evaluating to false means you skip the if statement code block.

You still need independent/complete expressions using the OR operator. You can split the expressions and see if they make sense separately:

if(bool === true){
//code
}
//you can see why this won't work
if(false){
//code
}

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.