Build a Boolean Check Function

So, the objectives are

  1. You should have a function called booWho that receives one argument.
  2. If the argument received is a boolean primitive, the function should return true.
  3. If the argument is any other value, the function should return false.
    that also includes the number 1 without any quotations ( (1), not “1”)

The thing is, I have tried to make number 1 false, by but whenever i declare that (x == 1) returns false, and i logged it, it still return true.

function booWho(x) {
  if (x == true || x == false) {
    return true;
  } else if (x == 1) {
    return false;
  } else {
    return false;
  }
}

console.log(booWho(1));

and the result is

// running tests 7.
BooWho should return true
// tests completed
// console output
true

Is there any way to fix this? I cant get past this level because of this issue.

What is test 7?

Have you tried other inputs for testing?

Have you considered strict equality?

How about using console.log(x.typeOf()) maybe that will show you the type of the parameter you send to the function.

Add 1 equal sign in
if (x == true || x == false)

so that it is

code removed by moderator

this will make it so that if the parameters are only equal to boolean values, it will return true, otherwise it will return false.

You can remove → else if (x== 1) { return false;}, because the code is no longer taking into account any true value rather than boolean values only.

Thanks for this, because I also had trouble in a different area, realized I just needed to have a default parameter for the function parameter to be called.

hi @redz

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.