Your if statement will evaluate whether your (condition) is true or false and execute (if it evaluates to true) the {statement} declared right after it.
Hint 2
In case your (condition) evaluates to false the {statement} won’t be executed and function will return the next return statement.
Solutions
Solution 1 (Click to Show/Hide)
// Setup
function trueOrFalse(wasThatTrue) {
// Only change code below this line.
if (wasThatTrue) {
return "Yes, that was true";
}
return "No, that was false";
// Only change code above this line.
}
Code Explanation
The function first evaluates if the condition (wasThatTrue) evaluates to true. If it does, ir returns the statement between the curly braces. If it doesn’t, it returns the next return statement outside them.
function myFunction(wasThatTrue) {
// Only change code below this line.
if(wasThatTrue) {
return "That was true";
}
return "That was false";
// Only change code above this line.
}
Yes, it’s correct. However to pass the challenge you need to type the strings exactly like it states. So you need to have it as “Yes, that was true” and “No, that was false”
// Example
function ourTrueOrFalse(isItTrue) {
if (isItTrue) {
return "Yes, it's true";
}
return "No, it's false";
}
// Setup
function trueOrFalse(wasThatTrue) {
// Only change code below this line.
if(wasThatTrue) {
return "Yes, that was true";
}
return "No, that was false";
// Only change code above this line.
}
// Change this value to test
trueOrFalse(false);