Basic Algorithm Scripting - Boo who

Tell us what’s happening:
Describe your issue in detail here.

Is it converting into boolean or checking boolean

Your code so far

function booWho(bool) {
  return bool === !!bool ? true : false;
}

booWho(null);

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0 Mercury/115.0

Challenge: Basic Algorithm Scripting - Boo who

Link to the challenge:

The double negation will cast it to the boolean.

I would suggest adding a couple of console.logs so you can see what’s happening
Also, since this is a working solution, I am going to wrap it in spoiler tags

function booWho(bool) {
  console.log(!bool) // null value returns true
  console.log(!!bool) // null value returns false
  
  return bool === !!bool ? true : false;
}

booWho(null);

Also, you technically don’t need the ternary here.

You could just return the strict equality expression

  return bool === !!bool;

thank you for your time


it return true but it test case it should written false how I got all test case passed

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.