Files

54 lines
1.2 KiB
Markdown
Raw Normal View History

2018-10-12 15:37:13 -04:00
---
title: Boo Who
---
# Boo Who
2018-10-12 15:37:13 -04:00
---
## Problem Explanation
2018-10-12 15:37:13 -04:00
This program is very simple, the trick is to understand what a boolean primitive is. The programs requires a true or false answer.
#### Relevant Links
* <a href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean' target='_blank' rel='nofollow'>Boolean</a>
---
## Hints
2018-10-12 15:37:13 -04:00
### Hint 1
2018-10-12 15:37:13 -04:00
You will need to check for the type of the parameter to see if it is a boolean.
2018-10-12 15:37:13 -04:00
### Hint 2
To check for the type of a parameter, you can use `typeof`.
2018-10-12 15:37:13 -04:00
### 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.
2018-10-12 15:37:13 -04:00
---
## Solutions
2018-10-12 15:37:13 -04:00
<details><summary>Solution 1 (Click to Show/Hide)</summary>
2018-10-12 15:37:13 -04:00
```javascript
function booWho(bool) {
return typeof bool === "boolean";
}
2018-10-12 15:37:13 -04:00
// test here
booWho(null);
2018-10-12 15:37:13 -04:00
```
#### Code Explanation
2018-10-12 15:37:13 -04:00
* 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`.
2018-10-12 15:37:13 -04:00
#### Relevant Links
* <a href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof' target='_blank' rel='nofollow'>typeof</a>
</details>