Help please! struggling to get it correct

Tell us what’s happening:

Your code so far


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

Link to the challenge:

You have two return statements in the same if statement. The first return will always execute, and the second return will never execute.

Take a look at the example in the challenge again.

1 Like

You also have two copies of the function. You only want one.

function trueOrFalse(isItTrue) {

^ This needs to be removed

1 Like

wasThatTrue function works correctly, if the second part ! on isItTrue that doesnt work. i cannot figure out how its solved

i have removed it…got last point left to do

Thanks

it makes a diffrence too

this point left to do

trueOrFalse(false) should return “No, that was false”

Cool, what’s your latest version of your code?

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

still the same

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

}

Hey @ShamGTR35, Next time you want to showcase your code, please use the ` backtick so it is easier to read, here is the example:

  • First of all,

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.

Note: Backticks are not single quotes.

markdown_Forums

Having something immediately after your return statement will NOT do anything.

1 Like

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.

can you show me how?
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

}