The only solution I could think of involved comparing the property of the Object class to a string. It is a concise and in my opinion good solution, but it isn’t doable with the knowledge from FCC alone. Does anyone have a solution that uses only functions covered by FCC?
My solution as follows:
function booWho(bool) {
// What is the new fad diet for ghost developers? The Boolean.
var myType = Object.prototype.toString.call(bool);
console.log(myType);
if(myType === "[object Boolean]") {
return true;
}
return false;
}
My solution was remarkably simple for this one.
Using only typeof
.
[details=Summary]
function booWho(bool) {
// What is the new fad diet for ghost developers? The Boolean.
if ( typeof bool === "boolean" ) {
return true;
}
else return false;
}
booWho(false);
This text will be hidden[/details]
1 Like
The solution that came to my mind is
function booWho(bool) {
return typeof bool === "boolean";
}
… but I’m not sure that operator has been covered by the time you reach booWho
. The challenge links to the boolean object, which can be used in a fairly clever way:
function booWho(bool) {
return Boolean(bool) === bool; // bool will only equal itself if it's a boolean
}
So, the answer to your question is yes, but it could be tough to pick up. I’m not sure what has been learned at this point in the course since I haven’t done these exercises in over a year, and none of it was my first exposure to JS.
1 Like
I did something very basic to pass the challenge:
[SPOILER]
function booWho(bool) {
return bool===true || bool===false;
}
[/SPOILER]
2 Likes
Thanks everybody, it’s always great to see different ways to solve a puzzle! Still trying to train my brain to do things the Javascript way (my brain prefers the Java way).
Hi everyone,
Here’s what I’ve got to solve mine:
[code]function booWho(bool) {
// What is the new fad diet for ghost developers? The Boolean.
return typeof bool === ‘boolean’ ? true : false;
}
booWho(null);[/code]
1 Like