{"componentChunkName":"component---src-templates-blog-post-js","path":"/blog/freecodecamp/frontend/javascript/fcc-boo-who-javascript-intermediate-algorithm/","result":{"data":{"site":{"siteMetadata":{"title":"Be Brav3"}},"markdownRemark":{"id":"e1ee96cc-0c9f-5dc5-89df-31706a3c4451","excerpt":"In FCC challenge Boo Who we’re trying to determine values being passed into the booWho function is a boolean. js function booWho(bool) { // What is the new fad…","html":"<p>In FCC challenge Boo Who we’re trying to determine values being passed into the booWho function is a boolean.</p>\n<p>[js]</p>\n<p>function booWho(bool) {</p>\n<p>// What is the new fad diet for ghost developers? The Boolean.</p>\n<p>return bool;</p>\n<p>}</p>\n<p>booWho(null);</p>\n<p>[/js]</p>\n<p>To determine whether the value in a variable is boolean or another type we can use the typeof operator. We can use the typeof operator and compare the variable to ‘boolean’.</p>\n<p>[js]</p>\n<p>if (typeof bool === ‘boolean’) {</p>\n<p>bool = true;</p>\n<p>} else {</p>\n<p>bool = false;</p>\n<p>}</p>\n<p>[/js]</p>\n<p>Looking at Rafase282’s solution, he had a much simpler solution. He used the following code to return true of false for a boolean type.</p>\n<p>[js]</p>\n<p>return typeof bool === ‘boolean’;</p>\n<p>[/js]</p>\n<p>typeof already returns true or false in my if condition so there was no need to assign true of false to bool and then returning it.</p>\n<p>My full code is below</p>\n<p>[js]</p>\n<p>function booWho(bool) {</p>\n<p>// What is the new fad diet for ghost developers? The Boolean.</p>\n<p>if (typeof bool === ‘boolean’) {</p>\n<p>bool = true;</p>\n<p>} else {</p>\n<p>bool = false;</p>\n<p>}</p>\n<p>console.log(bool);</p>\n<p>return bool;</p>\n<p>}</p>\n<p>booWho(null);</p>\n<p>booWho(true);</p>\n<p>booWho(false);</p>\n<p>booWho([1, 2, 3]);</p>\n<p>booWho([].slice);</p>\n<p>booWho({ ‘a’: 1 });</p>\n<p>booWho(1);</p>\n<p>booWho(NaN);</p>\n<p>booWho(‘a’);</p>\n<p>booWho(‘true’);</p>\n<p>booWho(‘false’);</p>\n<p>[/js]</p>","frontmatter":{"title":"FCC: Boo Who (JavaScript Intermediate Algorithm)","date":"September 22, 2016","description":null}}},"pageContext":{"slug":"/blog/freecodecamp/frontend/javascript/fcc-boo-who-javascript-intermediate-algorithm/","previous":{"fields":{"slug":"/blog/freecodecamp/frontend/javascript/fcc-missing-letters-javascript-intermediate-algorithm/"},"frontmatter":{"title":"FCC: Missing Letters (JavaScript Intermediate Algorithm)"}},"next":{"fields":{"slug":"/blog/freecodecamp/frontend/javascript/fcc-sorted-union-javascript-intermediate-algorithm/"},"frontmatter":{"title":"FCC: Sorted Union (JavaScript Intermediate Algorithm)"}}}}}