Conditional Logic

Conditional statement Conditional logic Boolean expression TRUE, FALSE

We’ve looked at how to draw on to the canvas, and how to move elements on the canvas over time. This week we’re going to look at how we can have a program make decisions while it’s running, how can it take different paths.


Relational operator

What can be true or false?

if (5 > 6) more than → FALSE

if (5 < 6) less than → TRUE

if (5 <= 6) more than or equals to → TRUE

if (5 >= 5) less than or equals to → TRUE

if (5 == 5) equals to → TRUE

if (5 != 5) does not equal to → FALSE

if (5 == "5")TRUE

Compares both the values and the types without performing type conversion. If the types are different, it returns false.

if (5 === "5")FALSE

Compares both the values and the types without performing type conversion. If the types are different, it returns false.