Your files never leave your device
Advertisement

Conditionals

Conditionals allow your code to make decisions. They run different blocks of code based on whether a boolean condition is true or false.

If / Else Statements

The most common conditional is the if statement. You can chain multiple conditions with else if.

Try It Yourself

        

Ternary Operator

A compact way to write simple if/else statements. Format: condition ? ifTrue : ifFalse.

Try It Yourself

        

Practice

Challenge 1: Write an if statement that logs "Even" if a number is even, and "Odd" otherwise. (Hint: use % 2)

Related Guides

Sponsored Utility
While You're Here
Sponsored Recommendations
Advertisement