Quick question about if statement in curriculum

Question: how on earth does the computer actually know what wasThatTrue even means? Is this just practicing if/else statements and we just assume that the computer already knows the value of wasThatTrue? This is super confusing to me.

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

}

Your browser information:

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

Challenge: Use Conditional Logic with If Statements

Link to the challenge:

That’s a very good question.

The computer is evaluating if the parameter passed in the function wasThatTrue is true or false.

If you look at the tests after they run, you can see that they tested true and false to check the function. If anything is passed as a parameter that evaluates true, it will return “Yes, that was true.”

Hope that makes sense.

1 Like

Thank you. However I am still confused. wasThatTrue was never defined in the code…I guess this is an example just so we can practice coding syntax for if statements?

Hi
wasThatTrue is an argument for the function and its a placeholder for any data you give when you calling it. It had defined when the whole function had defined and it might have any name like x, y or wasThatTrue.

3 Likes

Hey @EdenSweden!

I hope @borzoomv’s explanation makes sense to you. I am also going to link the lesson on passing values to functions as a refresher.

Let us know if you have any other questions.

2 Likes

wasThatTrue doesn’t need to be defined because it’s a parameter of the function.

1 Like

Ok, I guess I was reading into it more than necessary. Thank you.

1 Like

Thank you, I guess I was making it more complicated than it had to be. :stuck_out_tongue:

1 Like