## DEV Community is a community of 698,942 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

# Solving "Boo who" / freeCodeCamp Algorithm Challenges

Viren B
Originally published at virenb.cc Updated on ・2 min read

Post can also be found on my website https://virenb.cc/fcc-010-boo-who

Let's solve freeCodeCamp's Basic Algorithm Scripting Challenge, "Boo who"

## Our Starter Code (& Tests)

``````function booWho(bool) {
return bool;
}

booWho(null);

``````
``````// Tests
booWho(true) should return true.
booWho(false) should return true.
booWho([1, 2, 3]) should return false.
booWho([].slice) should return false.
booWho({ "a": 1 }) should return false.
booWho(1) should return false.
booWho(NaN) should return false.
booWho("a") should return false.
booWho("true") should return false.
booWho("false") should return false.
``````

### Our Instructions

Check if a value is classified as a boolean primitive. Return true or false.

Boolean primitives are true and false.

## Thoughts

• The argument's data types vary. Some booleans, strings, arrays, functions, etc.
• After reading the instructions and tests a few times, we must narrow in on true or false inputs/arguments only.
• We have to return a boolean, true or false.

### Further Thoughts

Reading the instructions again, the challenge is asking us to return true for boolean primatives.

(Looking at the tests, booWho(false) must return true.)

So, we must write a function, which returns true if the input is a true or false. If it is any other value, we must return false.

There is a built in operator in JavaScript, `typeof` which returns the data type.

MDN documentation: typeof

Some pseudo pseudocode:

``````booWho(input) {
if input type is true or false
return true
else
return false
}
``````

We are just checking the `typeof` of the argument.

## Solution

[SPOILER: SOLUTION TO CODE BELOW]

``````function booWho(bool) {
return typeof bool == 'boolean';
}
``````