Use Conditional

I can’t find the problem

function trueOrFalse(wasThatTrue) {

if(wasThatTrue); {

return "Yes, that was true";

}

return “No, that was false”;

// running tests

trueOrFalse(false)

should return the string

No, that was false

// tests completed

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

  **Your code so far**

function trueOrFalse(wasThatTrue) {
if(wasThatTrue); {
  return "Yes, that was true";
}
return "No, that was false";
// Only change code below this line
}

// Only change code above this line


  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36

Challenge: Use Conditional Logic with If Statements

Link to the challenge:

You have a semicolon (;) after the if condition. I think that is causing it to end the if there.

1 Like

In your code, the semicolon ends the if statement. The next code to run is a code block with a return statement inside it.

It basically becomes this (afaik):

function trueOrFalse(wasThatTrue) {
  if(wasThatTrue);

  {
    return "Yes, that was true";
  }

  return "No, that was false";

}

This is also why you can run the function without passing an argument and still get the “truthy” return value.

trueOrFalse()
// 'Yes, that was true'

You can have code blocks not “attached” to anything, they will create a scope as well.

function codeBlockScope() {
  {
    const youCantGetMe = "I'm not where you are";
  }

  console.log(youCantGetMe); // Reference Error
}

codeBlockScope();
2 Likes

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