Boolean algebra algo issue

Tell us what’s happening:
Describe your issue in detail here.

 So basically if anything except true or false falls in here it gives false but in case of 1 it gives back true. Tell me why?

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

  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36

Challenge: Boo who

Link to the challenge:

This is the weak comparison operator, which will coerce the left and right operands to matching types before comparing them.

but an algo is an algo that should work I want the reason why it’s not working.

An algorithm is an algorithm. The algorithm you have coded checks if the input variable bool can be coerced into either true or false, and everything in Javascript when coerced into a boolean value will either be true or false. There are no other options.

It is working as you coded it. == and === are very different in JavaScript.

1 Like

Thanks buddy! you’re amazing.

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