function trueOrFalse(wasThatTrue) {
// Only change code below this line
if (wasThatTrue) {
return "Yes, that was true";
return "No, that was false";
}
function trueOrFalse(isItTrue) {
if (isItTrue) {
return "Yes, that is true";
return "No, that is false";
}
// Only change code above this line
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36.
Challenge: Use Conditional Logic with If Statements
function trueOrFalse(wasThatTrue) {
// Only change code below this line
if (wasThatTrue) {
return "Yes, that was true";
return "No, that was false";
}
{
return "Yes, that is true";
"No, that is false";
}
// Only change code above this line
}
This piece isn’t doing anything useful for you now.
{
return “Yes, that is true”;
“No, that is false”;
}
This won’t quite work.
function trueOrFalse(wasThatTrue) {
// Only change code below this line
if (wasThatTrue) {
return “Yes, that was true”; // This is inside the if()
return “No, that was false”; // This is also inside the if()
}
// There isn't a return out here...
{
return “Yes, that is true”;
“No, that is false”;
}
This is the closest you have come to the answer. Like someone mentioned above, after “return” execution stops, so nothing else after it will be executed
function trueOrFalse(wasThatTrue) {
// Only change code below this line
if (wasThatTrue) {
return "Yes, that was true";
"No, that is false";
}
{
return "Yes, that is true";
"No, that is false";
}
// Only change code above this line
}
You cannot declare or put any code after the return statement. It should always be the last thing on a function ex:
function myFunc(a, b) {
return a + b;
//you can't put anything below the return statement or
//it will spit out an error saying unreachable code after return.
}
if (wasThatTrue) {
return “Yes, that was true”; // Anything below this until the } won't run
“No, that is false”; // This won't run since it's inside the if but after a }
// You need to 'return' this phrase in the right spot
}
// \/ You still should get rid of this stuff \/
// It's just confusing you
{
return “Yes, that is true”;
“No, that is false”;
}
// /\ Remove down to here /\
// Only change code above this line
}
In the example
function test (myCondition) {
if (myCondition) {
return "It was true";
}
return "It was false";
}
one return is inside the if and one is outside of it.
function trueOrFalse(wasThatTrue) {
// Only change code below this line
if (wasThatTrue) {
return "Yes, that was true";
"No, that was false";
}
{
return "Yes, that was true";
"No, that was false";
// Only change code above this line
}
still made a difference. both returns are in the if
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.
first thing first your code will not run because you have a syntax error: you need to have the same number of opening graph parenthesis and closing graph parenthesis, instead you have 3 opening ones and 2 closing ones.
function trueOrFalse(wasThatTrue) {
// Only change code below this line
if (wasThatTrue) {
return "Yes, that was true";
"No, that was false"; // This still is not a return. This still is not outside of the if statement.
}
{ // You still need to remove this
return "Yes, that was true"; // You still need to remove this
"No, that was false"; // You still need to remove this
// Only change code above this line
}