Boo who (Query on particularity of solution & query on FCC solution)

I have two questions in relation to this topic. I don’t want to publish spoilers so I’m going to try to just hint below as to my solution and the FCC solution to which I have a question.

I solved this equation with if/else, although I wasn’t able to do it within a single paratheses. E.g.
(if bool === true || false)
This returned only the first boolean I typed. Since I have included || why wouldn’t that allow both booleans to be considered?

The FCC solution uses typeof on bool and then triple-equals to “boolean”, which I find highly confusing. What is the purpose of this? First, isn’t “boolean” a string and what does that have to do with what is being checked for?

Thank you for your assistance in this matter.


Your browser information:

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

Link to the challenge:

take a look at the MDN on typeof – it returns a string. So by comparing the result of typeof(bool) to the string ‘boolean’, which is what typeof returns for a true/false, you can determine if it is, in fact, a boolean.

The issue with checking if (bool == true || bool == false) is the way javascript determines if a check is “truthy”. See more here.

Also, see how I did that double-comparison above? if (bool ===true || bool === false) – you need to treat each expression as though it were in isolation.

For goofs and giggles, open your console (via the ‘Developer Tools’ menu in your browser), and type the following few lines directly in the console. This will let you execute javascript line-by-line, seeing an immediate result.

var myBool = true       // Set some values
var myNum = 12.25
typeof(myBool)          // What does this line show?
typeof mynum           // Note that typeof or typeof(...) are the same
typeof({name: "foo", age: myNum})

The thing is, note that the returned value (the value that shows on the next line in the console) is surrounded by quotes. Why? Because it’s a string value. So compare to the string value you want to see, which in this case is ‘boolean’.