Basic JavaScript - Use Conditional Logic with If Statements

Tell us what’s happening:

Describe your issue in detail here.
What am I missing here?

Your code so far

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

  // 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/118.0.0.0 Safari/537.36

Challenge Information:

Basic JavaScript - Use Conditional Logic with If Statements

you did it exactly right, except you are testing the wrong variable in the if statement.

i would reccomend manually typing everything early on rather than copy-pasting it from the lesson, it makes you rely on yourself more and also forces you to learn better ways to type code in the editor!

to fix your code, just replace every instance of the variable trueOrFalse into wasThatTrue.

I didn’t copy…That’s all my doing!

good! then all you need is to focus on which variable names to type.
happy coding!

What wrong variable are you talking about?

in both if statements, you were checking the value of a variable called trueOrFalse, when you actually never defined it neaither as a variable or as a parameter.

the variable you are supposed to use is wasThatTrue, put that in between the brackets beside your if statements, and it should totally work.

like this:

if(wasThatTrue) {
  return "No, that was false";
}

Still even after doing so it didn’t change…what might be the problem kindly?

After doing what? Please post your updated code.

1 Like

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

// Only change code above this line

}
That’s my code what might be the problem with it?

The directions say
" Create an if statement inside the function to return Yes, that was true if the parameter wasThatTrue is true and return No, that was false otherwise."

Where are you getting trueOrFalse from in this line?

if(trueOrFalse)

You should only be checking wasThatTrue. You should only be using one if statement as well. If you do this

if(wasThatTrue) {
return “Yes, that was true”;
}
if(wasThatTrue) {
return “No, that was false”;
}

Notice how the if statements are checking the exact same thing? Do you know how you can return the false statement without putting it inside the if statement?

1 Like

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

// Only change code above this line

}
that the code
look at the response it keeps on bringing…
// running tests

trueOrFalse(false)

should return the string

No, that was false

// tests completed
Where might I be going wrong? I’m really confused.

Why are you still trying to use trueOrFalse in the if statements?

wasThatTrue is what you need to use. Forget about trueOrFalse. You are still trying to use two if statements when you need just one. So, lets take this one step at a time. What would your code look like if you only wanted to return “Yes, that was true”. We can start there and make sure thats right then we can add on the second step

2 Likes

The first “if” statement is fully functional, the issue is with the last one the one to return a “false” response.

If thats your first if statement still its not correct. After the ending } for the if statement try just returning the false statement and see what happens. If you have not yet you still need to change the above.

2 Likes

This is correct, it is the second one which is incorrect.

This

Is not correct.

It needs to be changed to be correct

2 Likes
  • trueOrFalse should be a function

  • Passed:trueOrFalse(true) should return a string

  • Passed:trueOrFalse(false) should return a string

  • Passed:trueOrFalse(true) should return the string Yes, that was true

  • Failed:trueOrFalse(false) should return the string No, that was false
    All this are correct…only the last one is the incorrect one.

Its not correct…even if you get the false response code correct you are still not using the correct variable in the if statement which I have pointed out multiple times. It will not pass if you try using trueOrFalse instead of wasThatTrue

2 Likes

Provide an example of what I should do, not a direct one though…kindly if you don’t mind.