# freeCodeCamp Challenge Guide: Boo who

freeCodeCamp Challenge Guide: Boo who
0

# Boo Who

## Problem Explanation

This program is very simple, the trick is to understand what a boolean primitive is. The programs requires a true or false answer.

## Hints

### Hint 1

You will need to check for the type of the parameter to see if it is a boolean.

### Hint 2

To check for the type of a parameter, you can use `typeof`.

### Hint 3

Since you must return true or false you can use if statements or just have it return the boolean used for the if statement.

## Solutions

Solution 1 (Click to Show/Hide)
``````function booWho(bool) {
return typeof bool === "boolean";
}

// test here
booWho(null);
``````

#### Code Explanation

• Uses the operator `typeof` to check if the variable is a boolean. If it is, it will return `true`. Otherwise, if it is any other type it will return `false`.

6 Likes

Why not this way?

``````function booWho(bool) {
return (bool === true || bool === false);
}``````
11 Likes

Can be performed using the builtin Boolean Function - only primitives remain equal to themselves with all other values converted to a booleans.

``````function booWho(bool) {

return Boolean(bool)===bool;
}``````
1 Like

I did this beautiful piece of work:

``````  if(bool === false){
return true;
}
return bool === true;
}``````
7 Likes

I wrote more code than necessary at first. Here was my initial code:

function booWho(bool) {
if(typeof(bool) === â€śbooleanâ€ť){
return true;
} else {
return false;
}
}

I realized the if statement is unnecessary, because the strict equality operator returns a true or false.

4 Likes

Did exactly the same thing (smh)

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

booWho(null);

``````
11 Likes

intermediate?? Shhmmmehh :stuck_out_tongue

``````function booWho(bool) {
var res = (bool === true || bool === false) ? (true) : (false);
return res;
}``````
1 Like

I wish we had haha reactionsâ€¦

2 Likes

``````function booWho(bool) {
// What is the new fad diet for ghost developers? The Boolean.
return bool === true || bool === false;
}

booWho(null);``````
2 Likes
``````function booWho(bool) {
// What is the new fad diet for ghost developers? The Boolean.

return !!bool === bool;
}

booWho(null);``````
1 Like

Thought I was pretty clever to come up with my simple solution until I realised it was supposed to be a simple answer:(

``````function booWho(bool) {
// What is the new fad diet for gho
if (typeof bool !== "boolean"){ return false;}
return true;
}

booWho(null);

``````
1 Like

I didnâ€™t remember that `typeof` returned a string, so I couldnâ€™t figure out the suggested solution.
Instead I did something a little overly complicated,

``````function booWho(bool) {
let test = true;
return typeof bool === typeof test;
}
``````
2 Likes

function booWho(bool) {
return typeof(bool) === â€śbooleanâ€ť;
}
booWho(false);

``````  function booWho(bool) {
// What is the new fad diet for ghost developers? The Boolean.
if(typeof(bool)==="boolean"){
return true;
}
else{
return false;
}
}
booWho(null);``````

I did the exact same thing, too!

A very basic solution is to check if the input is one of true or false

function booWho(bool) {
return ([true,false].indexOf(bool) > -1);
}

1 Like

This one was pretty easy. Although some of these other answers are pretty genius.

function booWho(bool) {
var thingy = Boolean(bool);
if (bool !== thingy){return false;}
return true;
}

booWho(false);