freeCodeCamp: JavaScript | Basic algo. & Data Structure


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

I used the above code and passed all the test cases.
I wasn’t expecting to pass with that code.
So, I checked if it’s one of the methods to pass in their hint section.
But It wasn’t there.

Is this code I tried makes sense or was the test code checking broken/had loopholes.?

I’m like: I don’t know what I did but it works :rofl:

Well, albeit looking strange your code is legit.

Expected behavior is to return true if the parameter is a boolean. Since you return true if the parameter is either strictly true or strictly false then it’s all good.

You could have used typeof for instance.

1 Like

Not sure what you are trying to test here, but any other argument except true and false will return false for this function.

booWho(true) => true
booWho(false) => true
booWho(1) => false
booWho(null) => false
booWho(undefined) => false
booWho('string') => false
1 Like

To be honest, I was just trying to console.log out and see what it does . As I am new to coding.
I was surprised to see that this alone passed the challenge. However, I was hoping that I’ll have to make some changes.
So I asked if what I did made any sense. If so, some explanation would be helpful.
Let me know you would solve this challenge

Thank you, Joo,
I just needed to know if this is as you said legit code or was it my luck that this code somehow broke past the test. :sweat_smile:

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