Need help: Boo Who

I don’t know where to go from here. It seems like im on the right track, but what am I missing here? I am having trouble making it return true. Help.

function booWho(bool) {
if(bool == null)
return true;
return false;


Hi! Try looking closely at the syntax for if statements— a bit more punctuation is required.

a Boolean is one of two values: true or false. Here, let me write out what your code is actually doing, in words (pseudocode):

I have a function, booWho, that takes a boolean value (true/false)
  - if that boolean value is null (not true or false):
    -- send back true (might happen, depends on if the user didn't send a boolean
    -- send back false (this line never happens, as I've already ended in the line above
- *NOW*, if there was an actual Boolean (true/false), do the default and send back an undefined

Inside the if statement, you return twice, so the first might happen. But, if the value passed in is either true or false, that if statement is completely skipped, and you drop right below it… where the function ends. And returns the default value, undefined.

Is that what you want to happen?

Oooo good catch.

@sarmpinheiro, have you learned about using the browser’s development tools yet? Specifically, the Console will tell you about any syntax errors your code is having.

Hi! I used the semicolon after the if statement and it returned true! But it wouldnt return false after that. What do I do from here to make it return true or false?

Sorry — semicolons are good! But you also need curly braces around the part of the code that you want to execute only if bool equals null . So it should look something like the following:

function isItThree(variable) {
  if (variable == 3) {
    return true;
  return false;

That way the first chunk of code (“return true”) executes only if your condition (“variable == 3” or “bool == null”) is true.

Well, it will work without the curly braces, executing only the line following the if statement.

But again, what (in your own words) is the behavior you want from the code? I know what the exercise expects, but it helps to slow down and paraphrase the challenge in your own style, to reframe the lesson, @sarmpinheiro.

1 Like

Cool! I hadn’t realized if statements worked without curly braces, but I see now that they can (if there’s only one line after the conditional, according to StackExchange?) Learned something, and sorry to lead you down a distracting path in trying to help.

1 Like

It works, but it’s generally frowned upon as it can be misleading. You’re doing fine and you’re learning along the way. Keep it going! :grin::grin:

1 Like